File tree Expand file tree Collapse file tree 1 file changed +35
-1
lines changed
Expand file tree Collapse file tree 1 file changed +35
-1
lines changed Original file line number Diff line number Diff 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 )) {
You can’t perform that action at this time.
0 commit comments