@@ -15,7 +15,14 @@ public function __construct($args) {
1515 $ this ->_controller = $ args ['controller ' ];
1616 $ this ->_caseSensitive = $ args ['caseSensitive ' ] ? true : false ;
1717 $ this ->_view = $ args ['view ' ] ? true : false ;
18- $ this ->_route = preg_replace ('/^\/?(.*?)\/?$/i ' ,'\\1 ' ,$ args ['route ' ]);
18+
19+ if ($ args ['route ' ]{0 } == '/ ' && !@preg_match ($ args ['route ' ], null )) {
20+ $ this ->_route = $ args ['route ' ];
21+ $ this ->_regex = true ;
22+ } else {
23+ $ this ->_route = preg_replace ('/^\/?(.*?)\/?$/i ' ,'\\1 ' , $ args ['route ' ]);
24+ }
25+
1926 $ this ->_tipsy = $ args ['tipsy ' ];
2027 $ this ->_method = $ args ['method ' ] == 'all ' ? '* ' : $ args ['method ' ];
2128
@@ -40,31 +47,40 @@ public function match($page) {
4047 }
4148 }
4249
43- $ pathParams = [];
44- $ paths = explode ('/ ' ,$ this ->_route );
45-
4650 // index page
4751 if (($ this ->_route === '' || $ this ->_route == '/ ' ) && ($ page === '' || $ page == '/ ' )) {
4852 return $ this ;
4953 }
5054
51- foreach ($ paths as $ key => $ path ) {
52- if (strpos ($ path ,': ' ) === 0 ) {
53- $ pathParams [$ key ] = substr ($ path ,1 );
54- }
55- }
55+ $ pathParams = [];
5656
57- $ r = preg_replace ('/:[a-z]+/i ' ,'.* ' ,$ this ->_route );
58- $ r = preg_replace ('/\// ' ,'\/ ' ,$ r );
57+ if ($ this ->_regex ) {
58+ if (preg_match ($ this ->_route , $ page , $ matches )) {
59+ $ this ->_routeParams = $ matches ;
60+ return $ this ;
61+ }
62+ } else {
5963
60- if (preg_match ('/^ ' .$ r .'$/ ' .($ this ->_caseSensitive ? '' : 'i ' ),$ page )) {
61- $ paths = explode ('/ ' ,$ page );
64+ $ paths = explode ('/ ' ,$ this ->_route );
6265
63- foreach ($ pathParams as $ key => $ path ) {
64- $ this ->_routeParams ->{$ path } = $ paths [$ key ];
66+ foreach ($ paths as $ key => $ path ) {
67+ if (strpos ($ path ,': ' ) === 0 ) {
68+ $ pathParams [$ key ] = substr ($ path ,1 );
69+ }
6570 }
6671
67- return $ this ;
72+ $ r = preg_replace ('/:[a-z]+/i ' ,'.* ' ,$ this ->_route );
73+ $ r = preg_replace ('/\// ' ,'\/ ' ,$ r );
74+
75+ if (preg_match ('/^ ' .$ r .'$/ ' .($ this ->_caseSensitive ? '' : 'i ' ),$ page )) {
76+ $ paths = explode ('/ ' ,$ page );
77+
78+ foreach ($ pathParams as $ key => $ path ) {
79+ $ this ->_routeParams ->{$ path } = $ paths [$ key ];
80+ }
81+
82+ return $ this ;
83+ }
6884 }
6985 return false ;
7086 }
0 commit comments