@@ -31,6 +31,7 @@ class GlobResource implements \IteratorAggregate, SelfCheckingResourceInterface
31
31
private $ hash ;
32
32
private $ forExclusion ;
33
33
private $ excludedPrefixes ;
34
+ private $ globBrace ;
34
35
35
36
/**
36
37
* @param string $prefix A directory prefix
@@ -47,6 +48,7 @@ public function __construct(string $prefix, string $pattern, bool $recursive, bo
47
48
$ this ->recursive = $ recursive ;
48
49
$ this ->forExclusion = $ forExclusion ;
49
50
$ this ->excludedPrefixes = $ excludedPrefixes ;
51
+ $ this ->globBrace = \defined ('GLOB_BRACE ' ) ? GLOB_BRACE : 0 ;
50
52
51
53
if (false === $ this ->prefix ) {
52
54
throw new \InvalidArgumentException (sprintf ('The path "%s" does not exist. ' , $ prefix ));
@@ -101,9 +103,43 @@ public function getIterator()
101
103
return ;
102
104
}
103
105
$ prefix = str_replace ('\\' , '/ ' , $ this ->prefix );
106
+ $ paths = null ;
104
107
105
- if (0 !== strpos ($ this ->prefix , 'phar:// ' ) && false === strpos ($ this ->pattern , '/**/ ' ) && (\defined ('GLOB_BRACE ' ) || false === strpos ($ this ->pattern , '{ ' ))) {
106
- $ paths = glob ($ this ->prefix .$ this ->pattern , GLOB_NOSORT | (\defined ('GLOB_BRACE ' ) ? GLOB_BRACE : 0 ));
108
+ if (0 !== strpos ($ this ->prefix , 'phar:// ' ) && false === strpos ($ this ->pattern , '/**/ ' )) {
109
+ if ($ this ->globBrace || false === strpos ($ this ->pattern , '{ ' )) {
110
+ $ paths = glob ($ this ->prefix .$ this ->pattern , GLOB_NOSORT | $ this ->globBrace );
111
+ } elseif (false === strpos ($ this ->pattern , '\\' )) {
112
+ $ segments = preg_split ('/\{([^{}]*+)\}/ ' , $ this ->pattern , -1 , PREG_SPLIT_DELIM_CAPTURE );
113
+ $ paths = [$ segments [0 ]];
114
+
115
+ for ($ i = 1 ; $ i < \count ($ segments ); $ i += 2 ) {
116
+ $ patterns = [];
117
+
118
+ foreach (explode (', ' , $ segments [$ i ]) as $ s ) {
119
+ foreach ($ paths as $ p ) {
120
+ $ patterns [] = $ p .$ s .$ segments [1 + $ i ];
121
+ }
122
+ }
123
+
124
+ $ paths = $ patterns ;
125
+ }
126
+
127
+ foreach ($ paths as $ i => $ p ) {
128
+ if (false !== strpos ($ p , '{ ' ) || false !== strpos ($ p , '} ' )) {
129
+ $ paths = null ;
130
+ break ;
131
+ }
132
+
133
+ $ paths [$ i ] = glob ($ this ->prefix .$ p , GLOB_NOSORT );
134
+ }
135
+
136
+ if (null !== $ paths ) {
137
+ $ paths = array_merge (...$ paths );
138
+ }
139
+ }
140
+ }
141
+
142
+ if (null !== $ paths ) {
107
143
sort ($ paths );
108
144
foreach ($ paths as $ path ) {
109
145
if ($ this ->excludedPrefixes ) {
0 commit comments