| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
namespace Symfony\Component\Translation\Extractor; |
| 13 |
|
| 14 |
use Symfony\Component\Translation\Exception\InvalidArgumentException; |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
> |
| 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 |
|
| 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 |
abstract protected function canBeExtracted(string $file): bool; |
| 59 |
|
| 60 |
abstract protected function extractFromDirectory(string|array $resource): iterable; |
| 61 |
} |