Skip to content

Commit

Permalink
增加withoutmiddleware方法
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Oct 6, 2024
1 parent f185332 commit d6540b9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/think/route/Dispatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// +----------------------------------------------------------------------
// | Author: liu21st <[email protected]>
// +----------------------------------------------------------------------
declare(strict_types=1);
declare (strict_types = 1);

namespace think\route;

Expand Down Expand Up @@ -88,7 +88,7 @@ protected function doRouteAfter(): void
$option = $this->rule->getOption();

// 添加中间件
if (!empty($option['middleware'])) {
if (empty($option['without_middleware']) && !empty($option['middleware'])) {
$this->app->middleware->import($option['middleware'], 'route');
}

Expand Down
12 changes: 12 additions & 0 deletions src/think/route/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,18 @@ public function middleware(string | array | Closure $middleware, ...$params)
return $this;
}

/**
* 不使用中间件
* @access public
* @return $this
*/
public function withoutMiddleware()
{
$this->option['without_middleware'] = true;

return $this;
}

/**
* 允许跨域
* @access public
Expand Down

0 comments on commit d6540b9

Please sign in to comment.