Skip to content

Commit

Permalink
分组Url自动调度的参数设置改成调度之前传入
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Oct 22, 2024
1 parent 1d4a6da commit f1ecf8e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/think/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ public function dispatch(Request $request, Closure | bool $withRoute = true)
}
$dispatch = $this->check($completeMatch);
} else {
$dispatch = $this->autoUrl($this->config['default_route'])
$dispatch = $this->urlDispatch($this->config['default_route'])
->check($this->request, $this->path(), $completeMatch);
}

Expand Down Expand Up @@ -784,7 +784,7 @@ public function check(bool $completeMatch = false)
} elseif ($this->config['url_route_must']) {
throw new RouteNotFoundException();
}
return $this->autoUrl($this->config['default_route'])
return $this->urlDispatch($this->config['default_route'])
->check($this->request, $url, $completeMatch);
}

Expand Down Expand Up @@ -839,7 +839,7 @@ public function auto(string $rule = '[:module]/[:controller]/[:action]', $route
* @param array $option 解析规则
* @return RuleItem
*/
public function autoUrl(array $option = []): RuleItem
protected function urlDispatch(array $option = []): RuleItem
{
return $this->group->urlDispatch($option);
}
Expand Down
16 changes: 8 additions & 8 deletions src/think/route/RuleGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,10 @@ public function check(Request $request, string $url, bool $completeMatch = false
}

if ($this->urlDispatch) {
// 分组默认URL路由规则
$result = $this->urlDispatch->check($request, $url, $completeMatch);
// 分组默认URL调度
$result = $this->urlDispatch
->option($this->getOption())
->check($request, $url, $completeMatch);
} elseif ($miss = $this->getMissRule($method)) {
// 未匹配所有路由的路由规则处理
$result = $miss->parseRule($request, '', $miss->getRoute(), $url, $miss->getOption());
Expand Down Expand Up @@ -363,7 +365,8 @@ protected function checkMergeRuleRegex(Request $request, array &$rules, string $
*/
public function autoUrl(array $option = [])
{
$this->urlDispatch($option);
$ruleItem = $this->urlDispatch($option);
$this->urlDispatch = $ruleItem;
return $this;
}

Expand All @@ -386,16 +389,13 @@ public function urlDispatch(array $option = []): RuleItem

$ruleItem = new UrlRuleItem($this->router, new RuleGroup($this->router), '_default_route_', $rule, $route);

$ruleItem = $ruleItem->default([
return $ruleItem->default([
'controller' => $this->config('default_controller'),
'action' => $this->config('default_action'),
])->pattern([
'controller' => '[A-Za-z0-9\.\_]+',
'action' => '[A-Za-z0-9\_]+',
])->option($this->getOption());

$this->urlDispatch = $ruleItem;
return $ruleItem;
]);
}

/**
Expand Down

0 comments on commit f1ecf8e

Please sign in to comment.