"Fossies" - the Fresh Open Source Software Archive 
Member "drupal-9.4.5/vendor/symfony/translation/Extractor/AbstractFileExtractor.php" (20 Jul 2022, 1989 Bytes) of package /linux/www/drupal-9.4.5.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
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 /**
24 * @param string|iterable $resource Files, a file or a directory
25 *
26 * @return iterable
27 */
28 protected function extractFiles($resource)
29 {
30 if (is_iterable($resource)) {
31 $files = [];
32 foreach ($resource as $file) {
33 if ($this->canBeExtracted($file)) {
34 $files[] = $this->toSplFileInfo($file);
35 }
36 }
37 } elseif (is_file($resource)) {
38 $files = $this->canBeExtracted($resource) ? [$this->toSplFileInfo($resource)] : [];
39 } else {
40 $files = $this->extractFromDirectory($resource);
41 }
42
43 return $files;
44 }
45
46 private function toSplFileInfo(string $file): \SplFileInfo
47 {
48 return new \SplFileInfo($file);
49 }
50
51 /**
52 * @param string $file
53 *
54 * @return bool
55 *
56 * @throws InvalidArgumentException
57 */
58 protected function isFile($file)
59 {
60 if (!is_file($file)) {
61 throw new InvalidArgumentException(sprintf('The "%s" file does not exist.', $file));
62 }
63
64 return true;
65 }
66
67 /**
68 * @param string $file
69 *
70 * @return bool
71 */
72 abstract protected function canBeExtracted($file);
73
74 /**
75 * @param string|array $resource Files, a file or a directory
76 *
77 * @return iterable files to be extracted
78 */
79 abstract protected function extractFromDirectory($resource);
80 }