PluginProbe
Metricool – Social media and site statistics / 2.1.1
Metricool – Social media and site statistics v2.1.1
2.1.1 2.1.0 2.0.2 2.0.1 2.0.0 1.27 trunk
metricool / vendor / _scoped / symfony / translation / Extractor / AbstractFileExtractor.php

AbstractFileExtractor.php in Metricool – Social media and site statistics 2.1.1, at vendor/_scoped/symfony/translation/Extractor/AbstractFileExtractor.php

69 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
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 Metricool\Vendor\Symfony\Component\Translation\Extractor;
12
13 use Metricool\Vendor\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 <[email protected]>
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