wp-user-avatar
/
third-party
/
vendor
/
symfony
/
translation
/
Extractor
/
AbstractFileExtractor.php
AbstractFileExtractor.php
2 months ago
ChainExtractor.php
2 months ago
ExtractorInterface.php
2 months ago
PhpExtractor.php
2 months ago
PhpStringTokenParser.php
2 months ago
AbstractFileExtractor.php
69 lines
| 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 | namespace ProfilePressVendor\Symfony\Component\Translation\Extractor; |
| 12 | |
| 13 | use ProfilePressVendor\Symfony\Component\Translation\Exception\InvalidArgumentException; |
| 14 | /** |
| 15 | * Base class used by classes that extract translation messages from files. |
| 16 | * |
| 17 | * @author Marcos D. Sánchez <marcosdsanchez@gmail.com> |
| 18 | */ |
| 19 | abstract class AbstractFileExtractor |
| 20 | { |
| 21 | /** |
| 22 | * @param string|iterable $resource Files, a file or a directory |
| 23 | * |
| 24 | * @return iterable |
| 25 | */ |
| 26 | protected function extractFiles($resource) |
| 27 | { |
| 28 | if (is_iterable($resource)) { |
| 29 | $files = []; |
| 30 | foreach ($resource as $file) { |
| 31 | if ($this->canBeExtracted($file)) { |
| 32 | $files[] = $this->toSplFileInfo($file); |
| 33 | } |
| 34 | } |
| 35 | } elseif (is_file($resource)) { |
| 36 | $files = $this->canBeExtracted($resource) ? [$this->toSplFileInfo($resource)] : []; |
| 37 | } else { |
| 38 | $files = $this->extractFromDirectory($resource); |
| 39 | } |
| 40 | return $files; |
| 41 | } |
| 42 | private function toSplFileInfo(string $file): \SplFileInfo |
| 43 | { |
| 44 | return new \SplFileInfo($file); |
| 45 | } |
| 46 | /** |
| 47 | * @return bool |
| 48 | * |
| 49 | * @throws InvalidArgumentException |
| 50 | */ |
| 51 | protected function isFile(string $file) |
| 52 | { |
| 53 | if (!is_file($file)) { |
| 54 | throw new InvalidArgumentException(sprintf('The "%s" file does not exist.', $file)); |
| 55 | } |
| 56 | return \true; |
| 57 | } |
| 58 | /** |
| 59 | * @return bool |
| 60 | */ |
| 61 | abstract protected function canBeExtracted(string $file); |
| 62 | /** |
| 63 | * @param string|array $resource Files, a file or a directory |
| 64 | * |
| 65 | * @return iterable |
| 66 | */ |
| 67 | abstract protected function extractFromDirectory($resource); |
| 68 | } |
| 69 |