Conditions | 3 |
Paths | 3 |
Total Lines | 33 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
19 | public function collectPathsRecursively($rootPath, $pattern) |
||
20 | { |
||
21 | if (!is_dir($rootPath)) { |
||
22 | return array(); |
||
23 | } |
||
24 | |||
25 | $directoryIterator = new \RecursiveDirectoryIterator( |
||
26 | $rootPath, |
||
27 | \RecursiveDirectoryIterator::FOLLOW_SYMLINKS |
||
28 | ); |
||
29 | |||
30 | $recursiveIterator = new \RecursiveIteratorIterator($directoryIterator); |
||
31 | |||
32 | $filesIterator = new \RegexIterator( |
||
33 | $recursiveIterator, |
||
34 | $pattern, |
||
35 | \RecursiveRegexIterator::GET_MATCH |
||
36 | ); |
||
37 | |||
38 | $files = array(); |
||
39 | |||
40 | foreach ($filesIterator as $info) { |
||
41 | $path = reset($info); |
||
42 | $files[substr($path, strlen($rootPath) + 1)] = $path; |
||
43 | } |
||
44 | |||
45 | $sequence = array_keys($files); |
||
46 | |||
47 | natsort($sequence); |
||
48 | |||
49 | return array_replace( |
||
50 | array_flip($sequence), |
||
51 | $files |
||
52 | ); |
||
55 |