auto() public static method

注册一个自动解析的URL路由
public static auto ( string $route ) : void
$route string 路由地址
return void
コード例 #1
0
ファイル: routeTest.php プロジェクト: samplecms/framework
 public function testCheckRouteGroup()
 {
     $request = Request::instance();
     Route::pattern(['id' => '\\d+']);
     Route::pattern('name', '\\w{6,25}');
     Route::group('group', [':id' => 'index/hello', ':name' => 'index/say']);
     $this->assertEquals(false, Route::check($request, 'empty/think'));
     $result = Route::check($request, 'group/think');
     $this->assertEquals(false, $result['module']);
     $result = Route::check($request, 'group/10');
     $this->assertEquals([null, 'index', 'hello'], $result['module']);
     $result = Route::check($request, 'group/thinkphp');
     $this->assertEquals([null, 'index', 'say'], $result['module']);
     Route::group('group2', function () {
         Route::group('group3', [':id' => 'index/hello', ':name' => 'index/say']);
         Route::rule(':name', 'index/hello');
         Route::auto('index');
     });
     $result = Route::check($request, 'group2/thinkphp');
     $this->assertEquals([null, 'index', 'hello'], $result['module']);
     $result = Route::check($request, 'group2/think');
     $this->assertEquals(['index', 'group2', 'think'], $result['module']);
     $result = Route::check($request, 'group2/group3/thinkphp');
     $this->assertEquals([null, 'index', 'say'], $result['module']);
     Route::group('group4', function () {
         Route::group('group3', [':id' => 'index/hello', ':name' => 'index/say']);
         Route::rule(':name', 'index/hello');
         Route::miss('index/__miss__');
     });
     $result = Route::check($request, 'group4/thinkphp');
     $this->assertEquals([null, 'index', 'hello'], $result['module']);
     $result = Route::check($request, 'group4/think');
     $this->assertEquals([null, 'index', '__miss__'], $result['module']);
     Route::group(['prefix' => 'prefix/'], function () {
         Route::rule('hello4/:name', 'hello');
     });
     Route::group(['prefix' => 'prefix/'], ['hello4/:name' => 'hello']);
     $result = Route::check($request, 'hello4/thinkphp');
     $this->assertEquals([null, 'prefix', 'hello'], $result['module']);
     Route::group('group5', [[':name', 'hello', ['method' => 'GET|POST']], ':id' => 'hello'], ['prefix' => 'prefix/']);
     $result = Route::check($request, 'group5/thinkphp');
     $this->assertEquals([null, 'prefix', 'hello'], $result['module']);
 }