@@ -170,14 +170,12 @@ class ORouter implements RouterInterface
170
170
'matchAll ' => '' ,
171
171
172
172
// auto route match @like yii framework
173
- 'autoRoute ' => [
174
- // If is True, will auto find the handler controller file.
175
- 'enable ' => false ,
176
- // The default controllers namespace, is valid when `'enable' = true`
177
- 'controllerNamespace ' => '' , // eg: 'app\\controllers'
178
- // controller suffix, is valid when `'enable' = true`
179
- 'controllerSuffix ' => '' , // eg: 'Controller'
180
- ],
173
+ // If is True, will auto find the handler controller file.
174
+ 'autoRoute ' => false ,
175
+ // The default controllers namespace, is valid when `'enable' = true`
176
+ 'controllerNamespace ' => '' , // eg: 'app\\controllers'
177
+ // controller suffix, is valid when `'enable' = true`
178
+ 'controllerSuffix ' => '' , // eg: 'Controller'
181
179
];
182
180
183
181
/** @var DispatcherInterface */
@@ -218,11 +216,7 @@ public function setConfig(array $config)
218
216
}
219
217
220
218
foreach ($ config as $ name => $ value ) {
221
- if ($ name === 'autoRoute ' ) {
222
- $ this ->config ['autoRoute ' ] = array_merge ($ this ->config ['autoRoute ' ], (array )$ value );
223
- } else {
224
- $ this ->config [$ name ] = $ value ;
225
- }
219
+ $ this ->config [$ name ] = $ value ;
226
220
}
227
221
}
228
222
@@ -494,7 +488,7 @@ public function match($path, $method)
494
488
// clear '//', '///' => '/'
495
489
$ path = rawurldecode (preg_replace ('#\/\/+# ' , '/ ' , $ path ));
496
490
$ method = strtoupper ($ method );
497
- $ number = $ this ->config ['tmpCacheNumber ' ];
491
+ $ number = ( int ) $ this ->config ['tmpCacheNumber ' ];
498
492
499
493
// setting 'ignoreLastSep'
500
494
if ($ path !== '/ ' && $ this ->config ['ignoreLastSep ' ]) {
@@ -582,7 +576,10 @@ public function match($path, $method)
582
576
}
583
577
584
578
// handle Auto Route
585
- if ($ handler = self ::matchAutoRoute ($ path , $ this ->config ['autoRoute ' ])) {
579
+ if (
580
+ $ this ->config ['autoRoute ' ] &&
581
+ ($ handler = self ::matchAutoRoute ($ path , $ this ->config ['controllerNamespace ' ], $ this ->config ['controllerSuffix ' ]))
582
+ ) {
586
583
return [$ path , [
587
584
'path ' => $ path ,
588
585
'handler ' => $ handler ,
@@ -594,25 +591,16 @@ public function match($path, $method)
594
591
}
595
592
596
593
/**
597
- * handle auto route match
598
- * when config `'autoRoute' => true`
594
+ * handle auto route match, when config `'autoRoute' => true`
599
595
* @param string $path The route path
600
- * @param array $opts The some options
601
- * contains: [
602
- * 'controllerNamespace' => '', // controller namespace. eg: 'app\\controllers'
603
- * 'controllerSuffix' => '', // controller suffix. eg: 'Controller'
604
- * ]
596
+ * @param string $controllerNamespace controller namespace. eg: 'app\\controllers'
597
+ * @param string $controllerSuffix controller suffix. eg: 'Controller'
605
598
* @return bool|callable
606
599
*/
607
- public static function matchAutoRoute ($ path , array $ opts )
600
+ public static function matchAutoRoute ($ path , $ controllerNamespace , $ controllerSuffix = '' )
608
601
{
609
- // not enabled
610
- if (!$ opts || !isset ($ opts ['enable ' ]) || !$ opts ['enable ' ]) {
611
- return false ;
612
- }
613
-
614
- $ cnp = $ opts ['controllerNamespace ' ];
615
- $ sfx = $ opts ['controllerSuffix ' ];
602
+ $ cnp = $ controllerNamespace ;
603
+ $ sfx = $ controllerSuffix ;
616
604
$ tmp = trim ($ path , '/- ' );
617
605
618
606
// one node. eg: 'home'
0 commit comments