Skip to content

Commit f674021

Browse files
authored
Merge pull request #86 from indykoning/feature/glob-folder-path
Allow wildcard in patches search folder path
2 parents adf4bf9 + 1f7dbe5 commit f674021

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

src/Utils/FileSystemUtils.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,47 @@ class FileSystemUtils
99
{
1010
public function collectFilePathsRecursively($rootPath, $pattern)
1111
{
12-
$paths = $this->collectPathsRecursively($rootPath, $pattern);
12+
if (strpos($rootPath, '*') !== false || strpos($rootPath, '?') !== false) {
13+
$paths = $this->collectGlobs($rootPath, $pattern);
14+
} else {
15+
$paths = $this->collectPathsRecursively($rootPath, $pattern);
16+
}
1317

1418
return array_filter($paths, function ($item) {
1519
return is_file($item);
1620
});
1721
}
1822

23+
public function collectGlobs($rootPath, $pattern)
24+
{
25+
$iterator = new \GlobIterator($rootPath);
26+
27+
$files = array();
28+
29+
foreach ($iterator as $info) {
30+
if($info->isDir()) {
31+
$files = [...$files, ...$this->collectPathsRecursively($info->getRealPath(), $pattern)];
32+
continue;
33+
}
34+
35+
if (!$info->isFile() || !preg_match($pattern, $info->getRealPath())) {
36+
continue;
37+
}
38+
39+
$path = $info->getRealPath();
40+
$files[$path] = $path;
41+
}
42+
43+
$sequence = array_keys($files);
44+
45+
natsort($sequence);
46+
47+
return array_replace(
48+
array_flip($sequence),
49+
$files
50+
);
51+
}
52+
1953
public function collectPathsRecursively($rootPath, $pattern)
2054
{
2155
if (!is_dir($rootPath)) {

0 commit comments

Comments
 (0)