This commit is contained in:
2023-08-25 00:26:53 +08:00
parent 41c0dc791e
commit 4ebe0c4d00
+18 -11
View File
@@ -40,6 +40,21 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
private array $methods = []; private array $methods = [];
/**
* @var Handler
*/
protected Handler $found;
/**
* @throws ReflectionException
*/
public function __construct()
{
$this->found = new Handler([di(NotFoundController::class), 'fail'], []);
}
/** /**
* @return array * @return array
*/ */
@@ -187,19 +202,11 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
/** /**
* @param string $path * @param string $path
* @param string $method * @param string $method
* @return Handler|null * @return Handler
* @throws ReflectionException
*/ */
public function query(string $path, string $method): ?Handler public function query(string $path, string $method): Handler
{ {
if ($method === 'OPTIONS') { return $this->methods[$method . '_' . $path] ?? $this->found;
$path = '/*';
}
$parent = $this->methods[$method . '_' . $path] ?? null;
if ($parent === null) {
return new Handler([di(NotFoundController::class), 'fail'], []);
}
return $parent;
} }