This commit is contained in:
xl
2023-07-15 01:51:38 +08:00
parent 20d70f3e80
commit e832a2721c
2 changed files with 2 additions and 24 deletions
-3
View File
@@ -197,9 +197,6 @@ class Router
$scanner->parse('App'); $scanner->parse('App');
$this->read_dir_file(APP_PATH . 'routes'); $this->read_dir_file(APP_PATH . 'routes');
$router = Kiri::getDi()->get(DataGrip::class)->get(ROUTER_TYPE_HTTP);
$router->reset();
} }
+2 -21
View File
@@ -39,25 +39,6 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
*/ */
private array $methods = []; private array $methods = [];
/**
* @return void
* @throws ReflectionException
*/
public function reset(): void
{
$middlewareManager = \Kiri::getDi()->get(MiddlewareManager::class);
/**
* @var string $method
* @var HashMap $handlers
*/
foreach ($this->methods as $method => $handler) {
$middleware = $middlewareManager->get($handler->getClass(), $handler->getMethod());
$this->methods[$method] = new HttpRequestHandler($middleware, $handler);
}
}
/** /**
* @return array * @return array
@@ -209,14 +190,14 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
* @return Handler|null * @return Handler|null
* @throws ReflectionException * @throws ReflectionException
*/ */
public function query(string $path, string $method): ?HttpRequestHandler public function query(string $path, string $method): ?Handler
{ {
if ($method === 'OPTIONS') { if ($method === 'OPTIONS') {
$path = '/*'; $path = '/*';
} }
$parent = $this->methods[$method . '_' . $path] ?? null; $parent = $this->methods[$method . '_' . $path] ?? null;
if ($parent === null) { if ($parent === null) {
return new HttpRequestHandler([], new Handler([di(NotFoundController::class), 'fail'], [])); return new Handler([di(NotFoundController::class), 'fail'], []);
} }
return $parent; return $parent;
} }