Skip to content

Commit

Permalink
refactor(router): move basePaths and groups to router provider
Browse files Browse the repository at this point in the history
  • Loading branch information
doyouhaobaby committed Feb 25, 2020
1 parent 111cb4d commit 63436e5
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 41 deletions.
48 changes: 48 additions & 0 deletions common/Infra/Provider/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,54 @@ class Router extends RouterProvider
'throttler' => 'Leevel\\Throttler\\Middleware\\Throttler',
];

/**
* 基础路径.
*
* @var array
*/
protected array $basePaths = [
'*' => [
'middlewares' => 'common',
],
'foo/*world' => [
],
'api/test' => [
'middlewares' => 'api',
],
':admin/*' => [
'middlewares' => 'admin_auth,cors',
],
'options/index' => [
'middlewares' => 'cors',
],
'admin/show' => [
'middlewares' => 'auth',
],
'/api/v1*' => [
'middlewares' => 'api',
],
'api/v2*' => [
'middlewares' => 'api',
],
'/web/v1*' => [
'middlewares' => 'web',
],
'web/v2*' => [
'middlewares' => 'web',
],
];

/**
* 分组.
*
* @var array
*/
protected array $groups = [
'pet',
'store',
'user',
];

/**
* 创建一个服务容器提供者实例.
*/
Expand Down
51 changes: 10 additions & 41 deletions router/router.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
*/

/**
* 路由.
*
* - 路由相关主要由路由服务提供者进行设置。
* - 大部分场景只需要使用基于路径的默认路由,不需要配置路由。
* - 其他定制路由都是基于 OpenAPI 的路由。
*
* @see 路由服务提供者 \Common\Infra\ProviderRouter
* @see 基于 OpenAPI 的路由 \App\App\Controller\Petstore\Store
*
* @OA\Info(
* description="This is a sample Petstore server. You can find
* out more about Swagger at
Expand All @@ -36,11 +45,8 @@ class _
}

/**
* leevels 为路由全局设置.
*
* @OA\Tag(
* name="pet",
* leevelGroup="pet",
* description="Everything about your Pets",
* @OA\ExternalDocumentation(
* description="Find out more",
Expand All @@ -49,12 +55,10 @@ class _
* )
* @OA\Tag(
* name="store",
* leevelGroup="store",
* description="Access to Petstore orders",
* )
* @OA\Tag(
* name="user",
* leevelGroup="user",
* description="Operations about user",
* @OA\ExternalDocumentation(
* description="Find out more about store",
Expand All @@ -68,44 +72,9 @@ class _
* @OA\ExternalDocumentation(
* description="Find out more about Swagger",
* url="http://swagger.io",
* leevels={
* "*": {
* "middlewares": "common"
* },
* "foo/*world": {
* },
* "api/test": {
* "middlewares": "api"
* },
* ":admin/*": {
* "middlewares": "admin_auth,cors"
* },
* "options/index": {
* "middlewares": "cors"
* },
* "admin/show": {
* "middlewares": "auth"
* },
* "/api/v1": {
* "middlewares": "api",
* "group": true
* },
* "api/v2": {
* "middlewares": "api",
* "group": true
* },
* "/web/v1": {
* "middlewares": "web",
* "group": true
* },
* "web/v2": {
* "middlewares": "web",
* "group": true
* }
* }
* )
*/
class _
class __
{
// 占位防止代码格式化工具将注释破坏
}

0 comments on commit 63436e5

Please sign in to comment.