From 4ebe0c4d00378df15bd69fb83ae66871f8eecbad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Fri, 25 Aug 2023 00:26:53 +0800 Subject: [PATCH] qqq --- src/RouterCollector.php | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/RouterCollector.php b/src/RouterCollector.php index 4bc6299..dc5cb0f 100644 --- a/src/RouterCollector.php +++ b/src/RouterCollector.php @@ -40,6 +40,21 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate private array $methods = []; + /** + * @var Handler + */ + protected Handler $found; + + + /** + * @throws ReflectionException + */ + public function __construct() + { + $this->found = new Handler([di(NotFoundController::class), 'fail'], []); + } + + /** * @return array */ @@ -187,19 +202,11 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate /** * @param string $path * @param string $method - * @return Handler|null - * @throws ReflectionException + * @return Handler */ - public function query(string $path, string $method): ?Handler + public function query(string $path, string $method): Handler { - if ($method === 'OPTIONS') { - $path = '/*'; - } - $parent = $this->methods[$method . '_' . $path] ?? null; - if ($parent === null) { - return new Handler([di(NotFoundController::class), 'fail'], []); - } - return $parent; + return $this->methods[$method . '_' . $path] ?? $this->found; }