Router

Config Example

//Router
'router' => [
    'single' => [
        ['GET', '/ping', [\App\services\DemoService::class, 'ping']],
        ['GET', '/redis', [\App\services\DemoService::class, 'redis', [\App\middlewares\Cors::class]]],
        ['GET', '/mysql', [\App\services\DemoService::class, 'mysql']],
        ['GET', '/http', [\App\services\DemoService::class, 'http']],
        ['GET', '/es', [\App\services\DemoService::class, 'es']],
        ['GET', '/file', [\App\services\DemoService::class, 'file']],
        ['GET', '/qiniu', [\App\services\DemoService::class, 'qiniu']],
    ],
    'group' => [
        '/admin' => [
            ['GET', '/ping', [\App\services\DemoService::class, 'ping']],
        ],
    ],
],

Format

[{Request Method}, {Path}, [{Handler}, {Handle Method}, [{Middleware1}, {Middleware2}...]]]

[{Middleware1}, {Middleware2}...] is optional.

Match Rules

// Matches /user/42, but not /user/xyz
['GET', '/user/{id:\d+}', [\App\services\UserService::class, 'get']]

// Matches /user/foobar, but not /user/foo/bar
['GET', '/user/{name}', [\App\services\UserService::class, 'get']]

// Matches /user/foo/bar as well
['GET', '/user/{name:.+}', [\App\services\UserService::class, 'get']]

Router Middleware

The router supports multiple middlewares. The priority of router middleware is lower than the one of global middleware.

['GET', '/redis', [\App\services\DemoService::class, 'redis', [\App\middlewares\Cors::class]]]

Last updated