This commit is contained in:
xl
2023-06-12 17:49:03 +08:00
parent 2d89f876ed
commit 41bd59591f
+8 -8
View File
@@ -49,7 +49,7 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
$this->methods = new HashMap();
$this->default = new HashMap();
$this->default->put('handler', new Handler([di(NotFoundController::class), 'fail'], []));
$this->default->put(':_handler', new Handler([di(NotFoundController::class), 'fail'], []));
}
@@ -158,10 +158,10 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
if ($hashMap->has($item)) {
$hashMap = $hashMap->get($item);
} else {
$hashMap->put($path, $hashMap = new HashMap());
$hashMap->put($item, $hashMap = new HashMap());
}
}
$hashMap->put('handler', $handler);
$hashMap->put(':_handler', $handler);
$this->registerMiddleware($handler->getClass(), $handler->getMethod());
}
@@ -214,24 +214,24 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
{
$parent = $this->methods->get($method);
if ($parent === null) {
return $this->default->get('handler');
return $this->default->get(':_handler');
}
if ($method === 'OPTIONS') {
$path = '/*';
}
$lists = str_split($path, 4);
foreach ($lists as $list) {
$parent = $parent->get($list);
foreach ($lists as $item) {
$parent = $parent->get($item);
if ($parent === null) {
return $this->default->get('handler');
return $this->default->get(':_handler');
}
}
// /** @var HashMap $parent */
// $parent = $parent->get($path, $this->default);
return $parent->get('handler');
return $parent->get(':_handler');
}