|
2 | 2 |
|
3 | 3 | namespace Printful\GettextCms; |
4 | 4 |
|
| 5 | +use FilesystemIterator; |
5 | 6 | use Gettext\Extractors\ExtractorInterface; |
6 | 7 | use Gettext\Extractors\ExtractorMultiInterface; |
7 | 8 | use Gettext\Extractors\JsCode; |
8 | 9 | use Gettext\Extractors\PhpCode; |
9 | 10 | use Gettext\Extractors\VueJs; |
10 | 11 | use Gettext\Translations; |
11 | | -use League\Flysystem\Adapter\Local; |
12 | | -use League\Flysystem\Filesystem; |
13 | | -use League\Flysystem\Plugin\ListFiles; |
14 | 12 | use Printful\GettextCms\Exceptions\GettextCmsException; |
15 | 13 | use Printful\GettextCms\Exceptions\InvalidPathException; |
16 | 14 | use Printful\GettextCms\Exceptions\UnknownExtractorException; |
17 | 15 | use Printful\GettextCms\Interfaces\MessageConfigInterface; |
18 | 16 | use Printful\GettextCms\Structures\ScanItem; |
| 17 | +use RecursiveDirectoryIterator; |
| 18 | +use RecursiveIteratorIterator; |
19 | 19 |
|
20 | 20 | /** |
21 | 21 | * Class extracts gettext function calls from source files and converts them to Translation objects |
@@ -55,7 +55,7 @@ public function extract(array $items, array $domains = null): array |
55 | 55 | } |
56 | 56 |
|
57 | 57 | /** @var Translations[] $allTranslations [domain => translations, ...] */ |
58 | | - $allTranslations = array_reduce($domains, function (&$carry, string $domain) use ($defaultDomain) { |
| 58 | + $allTranslations = array_reduce($domains, function ($carry, string $domain) use ($defaultDomain) { |
59 | 59 | $translations = new Translations(); |
60 | 60 |
|
61 | 61 | // When we scan for default domain, we have to specify an empty value |
@@ -160,23 +160,32 @@ private function resolveDirectoryFiles(ScanItem $item): array |
160 | 160 | { |
161 | 161 | $dir = realpath($item->path); |
162 | 162 |
|
163 | | - $adapter = new Local($dir); |
164 | | - $filesystem = new Filesystem($adapter); |
165 | | - $filesystem->addPlugin(new ListFiles()); |
166 | | - |
167 | | - $files = $filesystem->listFiles('', $item->recursive); |
| 163 | + if ($item->recursive) { |
| 164 | + $iterator = new RecursiveIteratorIterator( |
| 165 | + new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS) |
| 166 | + ); |
| 167 | + } else { |
| 168 | + $iterator = new FilesystemIterator($dir, FilesystemIterator::SKIP_DOTS); |
| 169 | + } |
168 | 170 |
|
169 | 171 | // If no extensions are given, fallback to known extensions |
170 | 172 | $extensions = $item->extensions ?: array_keys(self::EXTRACTORS); |
171 | 173 |
|
172 | | - // If extensions are set, filter other files out |
173 | | - $files = array_filter($files, function ($file) use ($item, $extensions) { |
174 | | - return isset($file['extension']) && in_array($file['extension'], $extensions); |
175 | | - }); |
| 174 | + $matchingPathnames = []; |
| 175 | + |
| 176 | + foreach ($iterator as $file) { |
| 177 | + if ($file->isDir()) { |
| 178 | + continue; |
| 179 | + } |
| 180 | + |
| 181 | + $extension = strtolower($file->getExtension()); |
| 182 | + |
| 183 | + if ($extensions && in_array($extension, $extensions)) { |
| 184 | + $matchingPathnames[] = $file->getRealPath(); |
| 185 | + } |
| 186 | + } |
176 | 187 |
|
177 | | - return array_map(function ($file) use ($dir) { |
178 | | - return $dir . DIRECTORY_SEPARATOR . $file['path']; |
179 | | - }, $files); |
| 188 | + return $matchingPathnames; |
180 | 189 | } |
181 | 190 |
|
182 | 191 | /** |
|
0 commit comments