This commit is contained in:
2023-10-17 20:39:08 +08:00
parent 0007cfeca6
commit 8fed901c0e
2 changed files with 10 additions and 4 deletions
+1 -1
View File
@@ -196,7 +196,7 @@ class Router
foreach ($router->getMethods() as $name => $method) { foreach ($router->getMethods() as $name => $method) {
$middlewares = $middleware->get($method->getClass(), $method->getMethod()); $middlewares = $middleware->get($method->getClass(), $method->getMethod());
$router->setMethod($name, new HttpRequestHandler($middlewares, $method)); $router->setHttpHandler($name, new HttpRequestHandler($middlewares, $method));
} }
} }
+9 -3
View File
@@ -47,6 +47,12 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
private array $methods = []; private array $methods = [];
/**
* @var array<string, HttpRequestHandler>
*/
protected array $httpHandler = [];
/** /**
* @var Handler * @var Handler
*/ */
@@ -80,9 +86,9 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
* @param HttpRequestHandler $handler * @param HttpRequestHandler $handler
* @return void * @return void
*/ */
public function setMethod(string $method, HttpRequestHandler $handler): void public function setHttpHandler(string $method, HttpRequestHandler $handler): void
{ {
$this->methods[$method] = $handler; $this->httpHandler[$method] = $handler;
} }
@@ -237,7 +243,7 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
*/ */
public function query(string $path, string $method): HttpRequestHandler public function query(string $path, string $method): HttpRequestHandler
{ {
return $this->methods[$method . '_' . $path] ?? new HttpRequestHandler([], $this->found); return $this->httpHandler[$method . '_' . $path] ?? new HttpRequestHandler([], $this->found);
} }