Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <fabien@symfony.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
 
12
namespace Symfony\Component\Translation\Extractor;
13
 
14
use Symfony\Component\Translation\Exception\InvalidArgumentException;
15
 
16
/**
17
 * Base class used by classes that extract translation messages from files.
18
 *
19
 * @author Marcos D. Sánchez <marcosdsanchez@gmail.com>
20
 */
21
abstract class AbstractFileExtractor
22
{
23
    protected function extractFiles(string|iterable $resource): iterable
24
    {
25
        if (is_iterable($resource)) {
26
            $files = [];
27
            foreach ($resource as $file) {
28
                if ($this->canBeExtracted($file)) {
29
                    $files[] = $this->toSplFileInfo($file);
30
                }
31
            }
32
        } elseif (is_file($resource)) {
33
            $files = $this->canBeExtracted($resource) ? [$this->toSplFileInfo($resource)] : [];
34
        } else {
35
            $files = $this->extractFromDirectory($resource);
36
        }
37
 
38
        return $files;
39
    }
40
 
41
    private function toSplFileInfo(string $file): \SplFileInfo
42
    {
43
        return new \SplFileInfo($file);
44
    }
45
 
46
    /**
47
     * @throws InvalidArgumentException
48
     */
49
    protected function isFile(string $file): bool
50
    {
51
        if (!is_file($file)) {
52
            throw new InvalidArgumentException(sprintf('The "%s" file does not exist.', $file));
53
        }
54
 
55
        return true;
56
    }
57
 
58
    /**
59
     * @return bool
60
     */
61
    abstract protected function canBeExtracted(string $file);
62
 
63
    /**
64
     * @return iterable
65
     */
66
    abstract protected function extractFromDirectory(string|array $resource);
67
}