1313
1414/**
1515 * Default implementation for Ant-style path patterns.
16- *
16+ *
1717 * <p>This was very much inspired (read: "kindly borrowed") from <a href="http://www.springsource.org/">Spring</a>.
1818 *
1919 */
20- class AntPathMatcher implements IAntPathMatcher {
21-
20+ class AntPathMatcher implements IAntPathMatcher
21+ {
2222 /**
2323 * (non-PHPdoc)
2424 * @see dflydev\util\antPathMatcher.IAntPathMatcher::isPattern()
@@ -48,9 +48,9 @@ public function matchStart($pattern, $path)
4848
4949 /**
5050 * Actually match the given <code>path</code> against the given <code>pattern</code>.
51- * @param string $pattern
52- * @param string $path
53- * @param boolean $fullMatch
51+ * @param string $pattern
52+ * @param string $path
53+ * @param boolean $fullMatch
5454 * @return boolean
5555 */
5656 protected function doMatch ($ pattern , $ path , $ fullMatch )
@@ -70,7 +70,7 @@ protected function doMatch($pattern, $path, $fullMatch)
7070 $ pattIdxEnd = count ($ pattDirs ) - 1 ;
7171 $ pathIdxStart = 0 ;
7272 $ pathIdxEnd = count ($ pathDirs ) - 1 ;
73-
73+
7474 // Match all elements up to the first **
7575 while ($ pattIdxStart <= $ pattIdxEnd and $ pathIdxStart <= $ pathIdxEnd ) {
7676 $ patDir = $ pattDirs [$ pattIdxStart ];
@@ -101,17 +101,16 @@ protected function doMatch($pattern, $path, $fullMatch)
101101 return false ;
102102 }
103103 }
104+
104105 return false ;
105- }
106- else if ($ pattIdxStart > $ pattIdxEnd ) {
106+ } elseif ($ pattIdxStart > $ pattIdxEnd ) {
107107 // String not exhausted, but pattern is. Failure.
108108 return false ;
109- }
110- else if (!$ fullMatch and "** " == $ pattDirs [$ pattIdxStart ]) {
109+ } elseif (!$ fullMatch and "** " == $ pattDirs [$ pattIdxStart ]) {
111110 // Path start definitely matches due to "**" part in pattern.
112111 return true ;
113112 }
114-
113+
115114 // up to last '**'
116115 while ($ pattIdxStart <= $ pattIdxEnd and $ pathIdxStart <= $ pathIdxEnd ) {
117116 $ patDir = $ pattDirs [$ pattIdxEnd ];
@@ -131,6 +130,7 @@ protected function doMatch($pattern, $path, $fullMatch)
131130 return false ;
132131 }
133132 }
133+
134134 return true ;
135135 }
136136
@@ -153,7 +153,7 @@ protected function doMatch($pattern, $path, $fullMatch)
153153 $ patLength = ($ patIdxTmp - $ pattIdxStart - 1 );
154154 $ strLength = ($ pathIdxEnd - $ pathIdxStart + 1 );
155155 $ foundIdx = -1 ;
156-
156+
157157 for ($ i = 0 ; $ i <= $ strLength - $ patLength ; $ i ++) {
158158 for ($ j = 0 ; $ j < $ patLength ; $ j ++) {
159159 $ subPat = $ pattDirs [$ pattIdxStart + $ j + 1 ];
@@ -165,44 +165,45 @@ protected function doMatch($pattern, $path, $fullMatch)
165165 $ foundIdx = $ pathIdxStart + $ i ;
166166 break ;
167167 }
168-
168+
169169 if ($ foundIdx == -1 ) {
170170 return false ;
171171 }
172-
172+
173173 $ pattIdxStart = $ patIdxTmp ;
174174 $ pathIdxStart = $ foundIdx + $ patLength ;
175-
175+
176176 }
177-
177+
178178 for ($ i = $ pattIdxStart ; $ i <= $ pattIdxEnd ; $ i ++) {
179179 if (!'** ' == $ pattDirs [$ i ]) {
180180 return false ;
181181 }
182182 }
183183
184184 return true ;
185-
185+
186186 }
187-
187+
188188 protected function tokenizeToStringArray ($ str , $ delimiter = DIRECTORY_SEPARATOR , $ trimTokens = true , $ ignoreEmptyTokens = true )
189189 {
190190 if ($ str === null ) { return null ; }
191191 $ tokens = array ();
192- foreach (explode ($ delimiter , $ str ) as $ token ) {
192+ foreach (explode ($ delimiter , $ str ) as $ token ) {
193193 if ($ trimTokens ) {
194194 $ token = trim ($ token );
195195 }
196196 if (!$ ignoreEmptyTokens or strlen ($ token )>0 ) {
197197 $ tokens [] = $ token ;
198198 }
199199 }
200+
200201 return $ tokens ;
201202 }
202-
203+
203204 private function matchStringsCallback ($ matches )
204205 {
205- switch ($ matches [0 ]) {
206+ switch ($ matches [0 ]) {
206207 case '? ' :
207208 return '. ' ;
208209 break ;
@@ -219,7 +220,8 @@ private function matchStringsCallback($matches)
219220 protected function matchStrings ($ pattern , $ str )
220221 {
221222 $ re = preg_replace_callback ('([\?\*\.\+]) ' , array ($ this , 'matchStringsCallback ' ), $ pattern );
223+
222224 return preg_match ('/ ' .$ re .'/ ' , $ str );
223225 }
224226
225- }
227+ }
0 commit comments