@@ -51,21 +51,7 @@ public function getUrl()
5151 */
5252 public function match ($ patterns )
5353 {
54- $ url = $ this ->getUrl ();
55-
56- if (!is_array ($ patterns )) {
57- $ patterns = array ($ patterns );
58- }
59-
60- foreach ($ patterns as $ pattern ) {
61- $ pattern = str_replace (array ('\\* ' , '\\? ' ), array ('.+ ' , '? ' ), preg_quote ($ pattern , '| ' ));
62-
63- if (preg_match ('|^ ' .$ pattern .'$|i ' , $ url )) {
64- return true ;
65- }
66- }
67-
68- return false ;
54+ return static ::urlMatches ($ this ->getUrl (), $ patterns );
6955 }
7056
7157
@@ -378,4 +364,29 @@ public function getAbsolute($url)
378364
379365 return $ this ->getScheme ().':// ' .$ this ->getHost ().$ this ->getPath ().$ url ;
380366 }
367+
368+
369+ /**
370+ * Check if the url match with a specific pattern. The patterns only accepts * and ?
371+ *
372+ * @param string|array $patterns The pattern or an array with various patterns
373+ *
374+ * @return boolean True if the url match, false if not
375+ */
376+ protected static function urlMatches ($ url , $ patterns )
377+ {
378+ if (!is_array ($ patterns )) {
379+ $ patterns = array ($ patterns );
380+ }
381+
382+ foreach ($ patterns as $ pattern ) {
383+ $ pattern = str_replace (array ('\\* ' , '\\? ' ), array ('.+ ' , '? ' ), preg_quote ($ pattern , '| ' ));
384+
385+ if (preg_match ('|^ ' .$ pattern .'$|i ' , $ url )) {
386+ return true ;
387+ }
388+ }
389+
390+ return false ;
391+ }
381392}
0 commit comments