From 3499d6510476e27a01890702962d225f5bbfdcc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Wed, 8 Sep 2021 15:28:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- http-helper/Route/Router.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/http-helper/Route/Router.php b/http-helper/Route/Router.php index 5a41e957..59db754f 100644 --- a/http-helper/Route/Router.php +++ b/http-helper/Route/Router.php @@ -394,17 +394,17 @@ class Router extends HttpService implements RouterInterface } /** - * @param string|null $explode + * @param array|null $explode * @return Node|null * 查找指定路由 * @throws Exception */ - public function tree_search(?string $explode): ?Node + public function tree_search(?array $explode): ?Node { if (empty($this->nodes)) { return null; } - return $this->nodes[$explode] ?? null; + $parent = $this->nodes[$explode] ?? null; if (!($parent instanceof Node)) { return null; } @@ -425,7 +425,6 @@ class Router extends HttpService implements RouterInterface public function split($path): ?array { $path = $this->addPrefix() . '/' . ltrim($path, '/'); - return [$path]; if ($path === '/') { return ['/']; } @@ -507,13 +506,10 @@ class Router extends HttpService implements RouterInterface { $uri = $request->getUri(); if ($request->isMethod('OPTIONS')) { - $node = $this->tree_search('/*'); + $node = $this->tree_search(['*']); } if (!isset($node)) { - $node = $this->tree_search($uri->getPath()); - } - if (!($node instanceof Node)) { - return null; + $node = $this->tree_search($uri->getExplode()); } return $node; }