@@ -30,22 +30,22 @@ public function registerFilter( string $Name, Filter $Filter ): void
3030 }
3131
3232 /**
33- * @param string $Name
33+ * @param string $routeName
3434 * @return Filter
3535 * @throws \Exception
3636 */
3737
38- public function getFilter ( string $ Name ) : Filter
38+ public function getFilter ( string $ routeName ) : Filter
3939 {
4040 $ Filter = null ;
4141
42- if ( array_key_exists ( $ Name , $ this ->_FilterRegistry ) )
42+ if ( array_key_exists ( $ routeName , $ this ->_FilterRegistry ) )
4343 {
44- $ Filter = $ this ->_FilterRegistry [ $ Name ];
44+ $ Filter = $ this ->_FilterRegistry [ $ routeName ];
4545 }
4646 else
4747 {
48- throw new \Exception ( "Filter $ Name not registered. " );
48+ throw new \Exception ( "Filter $ routeName not registered. " );
4949 }
5050
5151 return $ Filter ;
@@ -140,6 +140,21 @@ protected function isRouteWithParams( RouteMap $Route ) : bool
140140 */
141141 protected function processRoute ( RouteMap $ Route , $ Uri ) : ?array
142142 {
143+ if ( !$ Uri )
144+ {
145+ $ Uri = '/ ' ;
146+ }
147+ else if ( $ Uri [ 0 ] != '/ ' )
148+ {
149+ $ Uri = '/ ' . $ Uri ;
150+ }
151+
152+ if ( strlen ( $ Uri ) > 1 && $ Uri [ strlen ( $ Uri ) - 1 ] == "/ " )
153+ {
154+ $ string = new NString ( $ Uri );
155+ $ Uri = $ string ->left ( $ string ->length () - 1 );
156+ }
157+
143158 // Does route have parameters?
144159
145160 if ( $ this ->isRouteWithParams ( $ Route ) )
@@ -155,15 +170,6 @@ protected function processRoute( RouteMap $Route, $Uri ) : ?array
155170 }
156171 else
157172 {
158- if ( !$ Uri )
159- {
160- $ Uri = '/ ' ;
161- }
162- else if ( $ Uri [ 0 ] != '/ ' )
163- {
164- $ Uri = '/ ' . $ Uri ;
165- }
166-
167173 if ( $ Route ->Path == $ Uri )
168174 {
169175 return [];
@@ -179,6 +185,7 @@ protected function processRoute( RouteMap $Route, $Uri ) : ?array
179185 * @return array
180186 * @throws \Exception
181187 */
188+
182189 protected function processRouteWithParameters ( RouteMap $ Route , string $ Uri ) : array
183190 {
184191 $ Details = $ Route ->parseParams ();
@@ -192,9 +199,10 @@ protected function processRouteWithParameters( RouteMap $Route, string $Uri ) :
192199 * @param array $Details
193200 * @return array
194201 */
202+
195203 protected function extractRouteParams ( string $ Uri , array $ Details ) : array
196204 {
197- if ( $ Uri && $ Uri [ 0 ] == '/ ' )
205+ if ( $ Uri && $ Uri [ 0 ] == '/ ' )
198206 {
199207 $ String = new NString ( $ Uri );
200208 $ Uri = $ String ->right ( $ String ->length () - 1 );
@@ -213,12 +221,10 @@ protected function extractRouteParams( string $Uri, array $Details ) : array
213221 }
214222
215223 $ action = $ Details [ $ iOffset ][ 'action ' ];
216- if ( $ action )
224+
225+ if ( $ action && $ action != $ Part )
217226 {
218- if ( $ action != $ Part )
219- {
220- return [];
221- }
227+ return [];
222228 }
223229 else
224230 {
@@ -296,15 +302,7 @@ public function getRoute( int $Method, string $Uri ) : ?RouteMap
296302 {
297303 if ( $ Params )
298304 {
299- if ( is_array ( $ Params ) )
300- {
301- $ Route ->Parameters = $ Params ;
302- }
303- else
304- {
305- $ Route ->Parameters = [];
306- }
307-
305+ $ Route ->Parameters = $ Params ;
308306 return $ Route ;
309307 }
310308 }
@@ -374,7 +372,9 @@ function run( array $Argv = [] ) : mixed
374372 $ Type = $ Argv [ 'type ' ];
375373 }
376374
377- $ Route = $ this ->getRoute ( RequestMethod::getType ( $ Type ), $ Argv [ 'route ' ] );
375+ $ Uri = $ Argv [ 'route ' ];
376+
377+ $ Route = $ this ->getRoute ( RequestMethod::getType ( $ Type ), $ Uri );
378378
379379 if ( !$ Route )
380380 {
@@ -394,14 +394,7 @@ function run( array $Argv = [] ) : mixed
394394
395395 if ( array_key_exists ( 'extra ' , $ Argv ) )
396396 {
397- if ( is_array ( $ Route ->Parameters ) )
398- {
399- $ Route ->Parameters = array_merge ( $ Route ->Parameters , $ Argv [ 'extra ' ] );
400- }
401- else
402- {
403- $ Route ->Parameters = $ Argv [ 'extra ' ];
404- }
397+ $ Route ->Parameters = array_merge ( $ Route ->Parameters , $ Argv [ 'extra ' ] );
405398 }
406399
407400 $ Route ->Parameters = array_merge ( $ Route ->Parameters , $ Route ->Payload );
0 commit comments