18
18
use RecursiveDirectoryIterator ;
19
19
use RecursiveIteratorIterator ;
20
20
use SplFileInfo ;
21
+ use AppendIterator ;
21
22
22
23
/**
23
24
* A directory in a project.
24
25
*/
25
26
class Directory
26
27
{
27
28
/**
28
- * @var string
29
+ * @var array
29
30
*/
30
- private $ path ;
31
+ private $ paths ;
31
32
32
33
/**
33
34
* @var string
34
35
*/
35
36
private $ workingDirectory ;
36
37
37
- public function __construct ($ path , $ workingDirectory )
38
+ public function __construct ($ paths , $ workingDirectory )
38
39
{
39
- $ this ->path = $ path ;
40
+ if (is_string ($ paths )) {
41
+ $ paths = array ($ paths );
42
+ }
43
+
44
+ $ this ->paths = $ paths ;
40
45
$ this ->workingDirectory = $ workingDirectory ;
41
46
}
42
47
@@ -47,22 +52,28 @@ public function findAllPhpFilesRecursivly()
47
52
{
48
53
$ workingDirectory = $ this ->workingDirectory ;
49
54
50
- return
51
- new CallbackTransformIterator (
52
- new CallbackFilterIterator (
53
- new RecursiveIteratorIterator (
54
- new RecursiveDirectoryIterator ($ this ->path ),
55
- RecursiveIteratorIterator::LEAVES_ONLY
55
+ $ iterator = new AppendIterator ;
56
+
57
+ foreach ($ this ->paths as $ path ) {
58
+ $ iterator ->append (
59
+ new CallbackTransformIterator (
60
+ new CallbackFilterIterator (
61
+ new RecursiveIteratorIterator (
62
+ new RecursiveDirectoryIterator ($ path ),
63
+ RecursiveIteratorIterator::LEAVES_ONLY
64
+ ),
65
+ function (SplFileInfo $ file ) {
66
+ return substr ($ file ->getFilename (), -4 ) === ".php " ;
67
+ }
56
68
),
57
- function (SplFileInfo $ file ) {
58
- return substr ($ file ->getFilename (), - 4 ) === " .php " ;
69
+ function ($ file) use ( $ workingDirectory ) {
70
+ return File:: createFromPath ($ file ->getPathname (), $ workingDirectory ) ;
59
71
}
60
- ),
61
- function ($ file ) use ($ workingDirectory ) {
62
- return File::createFromPath ($ file ->getPathname (), $ workingDirectory );
63
- }
64
- )
65
- ;
72
+ )
73
+ );
74
+ }
75
+
76
+ return $ iterator ;
66
77
}
67
78
}
68
79
0 commit comments