Skip to content

Commit

Permalink
fix: Recursively search directories
Browse files Browse the repository at this point in the history
  • Loading branch information
kubotak-is committed Dec 2, 2021
1 parent 77d6051 commit 13fe211
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public function getDirs(): array
return $this->dirs;
}

public function getExtensions(): string
public function getExtensions(): array
{
return implode(",", $this->extensions);
return $this->extensions;
}
}
24 changes: 23 additions & 1 deletion src/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,28 @@ class File
{
public static function getFiles(string $dir, Config $config): array
{
return glob(getcwd(). '/' . $dir . '/**/*.{' . $config->getExtensions() . '}', GLOB_BRACE) ?? [];
$files = [];
self::rglob(getcwd(). '/' . $dir, $config->getExtensions(), $files);
return $files;
}

public static function rglob(string $dir, array $exts, array &$results=[]) {
$ls = glob($dir);

if (is_array($ls)) {
foreach ($ls as $item) {
if (is_dir($item)) {
self::rglob($item . '/*', $exts, $results);
}
if (is_file($item)) {
$ext = substr($item, strrpos($item, '.') + 1);
if (in_array($ext, $exts, true)) {
$results[] = $item;
}
}
}
}

return $results;
}
}

0 comments on commit 13fe211

Please sign in to comment.