@@ -111,7 +111,9 @@ public function getIterator()
111
111
$ prefix = str_replace ('\\' , '/ ' , $ this ->prefix );
112
112
$ paths = null ;
113
113
114
- if (!str_starts_with ($ this ->prefix , 'phar:// ' ) && !str_contains ($ this ->pattern , '/**/ ' )) {
114
+ if ('' === $ this ->pattern && is_file ($ prefix )) {
115
+ $ paths = [$ this ->prefix ];
116
+ } elseif (!str_starts_with ($ this ->prefix , 'phar:// ' ) && !str_contains ($ this ->pattern , '/**/ ' )) {
115
117
if ($ this ->globBrace || !str_contains ($ this ->pattern , '{ ' )) {
116
118
$ paths = glob ($ this ->prefix .$ this ->pattern , \GLOB_NOSORT | $ this ->globBrace );
117
119
} elseif (!str_contains ($ this ->pattern , '\\' ) || !preg_match ('/ \\\\[,{}]/ ' , $ this ->pattern )) {
@@ -172,14 +174,21 @@ function (\SplFileInfo $file, $path) {
172
174
throw new \LogicException (sprintf ('Extended glob pattern "%s" cannot be used as the Finder component is not installed. ' , $ this ->pattern ));
173
175
}
174
176
177
+ if (is_file ($ prefix = $ this ->prefix )) {
178
+ $ prefix = \dirname ($ prefix );
179
+ $ pattern = basename ($ prefix ).$ this ->pattern ;
180
+ } else {
181
+ $ pattern = $ this ->pattern ;
182
+ }
183
+
175
184
$ finder = new Finder ();
176
- $ regex = Glob::toRegex ($ this -> pattern );
185
+ $ regex = Glob::toRegex ($ pattern );
177
186
if ($ this ->recursive ) {
178
187
$ regex = substr_replace ($ regex , '(/|$) ' , -2 , 1 );
179
188
}
180
189
181
- $ prefixLen = \strlen ($ this -> prefix );
182
- foreach ($ finder ->followLinks ()->sortByName ()->in ($ this -> prefix ) as $ path => $ info ) {
190
+ $ prefixLen = \strlen ($ prefix );
191
+ foreach ($ finder ->followLinks ()->sortByName ()->in ($ prefix ) as $ path => $ info ) {
183
192
$ normalizedPath = str_replace ('\\' , '/ ' , $ path );
184
193
if (!preg_match ($ regex , substr ($ normalizedPath , $ prefixLen )) || !$ info ->isFile ()) {
185
194
continue ;
0 commit comments