@@ -39,6 +39,11 @@ class File_Iterator extends FilterIterator
39
39
*/
40
40
protected $ basepath ;
41
41
42
+ /**
43
+ * @var bool
44
+ */
45
+ private $ excludeAll = FALSE ;
46
+
42
47
/**
43
48
* @param Iterator $iterator
44
49
* @param array $suffixes
@@ -58,6 +63,11 @@ public function __construct(Iterator $iterator, array $suffixes = array(), array
58
63
$ basepath = NULL ;
59
64
} else {
60
65
foreach ($ exclude as &$ _exclude ) {
66
+ if (self ::isExcludeParentOrSame ($ _exclude , $ basepath )) {
67
+ $ this ->excludeAll = TRUE ;
68
+ continue ;
69
+ }
70
+
61
71
$ _exclude = str_replace ($ basepath , '' , $ _exclude );
62
72
}
63
73
}
@@ -100,6 +110,10 @@ public function accept()
100
110
*/
101
111
protected function acceptPath ($ path )
102
112
{
113
+ if ($ this ->excludeAll ) {
114
+ return FALSE ;
115
+ }
116
+
103
117
foreach ($ this ->exclude as $ exclude ) {
104
118
if (strpos ($ path , $ exclude ) === 0 ) {
105
119
return FALSE ;
@@ -155,4 +169,19 @@ protected function acceptSubString($filename, array $subStrings, $type)
155
169
156
170
return $ matched ;
157
171
}
172
+
173
+ private static function isExcludeParentOrSame ($ exclude , $ basepath )
174
+ {
175
+ if ($ exclude === $ basepath ) {
176
+ return TRUE ;
177
+ }
178
+
179
+ $ excludeWithSeparator = $ exclude . DIRECTORY_SEPARATOR ;
180
+ $ prefixLength = strlen ($ excludeWithSeparator );
181
+ if ($ excludeWithSeparator === substr ($ basepath , 0 , $ prefixLength )) {
182
+ return TRUE ;
183
+ }
184
+
185
+ return FALSE ;
186
+ }
158
187
}
0 commit comments