Skip to content

Commit

Permalink
feat: add unlimited levels of route group and middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
onanying committed Apr 23, 2023
1 parent e62d519 commit 5bcffc0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
22 changes: 16 additions & 6 deletions docs/3.0/zh-cn/mix-vega.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,11 @@ $vega->handle('/hello', function (Mix\Vega\Context $ctx) {

```php
$vega = new Mix\Vega\Engine();
$sub = $vega->pathPrefix('/foo');
$sub->handle('/bar1', function (Mix\Vega\Context $ctx) {
$foo = $vega->pathPrefix('/foo');
$bar = $foo->pathPrefix('/bar');
$bar->handle('/baz', function (Mix\Vega\Context $ctx) { // path=/foo/bar/baz
$ctx->string(200, 'hello, world!');
})->methods('GET');
$sub->handle('/bar2', function (Mix\Vega\Context $ctx) {
$ctx->string(200, 'hello1, world!');
})->methods('GET');
```

## 参数获取
Expand Down Expand Up @@ -408,7 +406,9 @@ $vega->handle('/hello', $func, function (Mix\Vega\Context $ctx) {
})->methods('GET');
```

配置全局中间件,即便没有匹配到路由也会执行
配置全局中间件

- 全局中间件:即便没有匹配到路由也会执行

```php
$vega = new Mix\Vega\Engine();
Expand All @@ -417,6 +417,16 @@ $vega->use(function (Mix\Vega\Context $ctx) {
});
```

- 路由前缀全局中间件

```php
$vega = new Mix\Vega\Engine();
$foo = $vega->pathPrefix('/foo');
$foo->use(function (Mix\Vega\Context $ctx) {
$ctx->next();
});
```

前置中间件

```php
Expand Down
4 changes: 2 additions & 2 deletions src/vega/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,9 @@ $vega->handle('/hello', $func, function (Mix\Vega\Context $ctx) {
})->methods('GET');
```

配置全局中间件,即便没有匹配到路由也会执行
配置全局中间件

- 全局中间件
- 全局中间件:即便没有匹配到路由也会执行

```php
$vega = new Mix\Vega\Engine();
Expand Down
4 changes: 2 additions & 2 deletions src/vega/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,9 @@ $vega->handle('/hello', $func, function (Mix\Vega\Context $ctx) {
})->methods('GET');
```

Configure the global middleware, it will be executed even if the route is not matched
Configure the global middleware

- Global middleware
- Global middleware: it will be executed even if the route is not matched

```php
$vega = new Mix\Vega\Engine();
Expand Down

0 comments on commit 5bcffc0

Please sign in to comment.