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->methods = new HashMap();
$this->default = 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)) { if ($hashMap->has($item)) {
$hashMap = $hashMap->get($item); $hashMap = $hashMap->get($item);
} else { } 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()); $this->registerMiddleware($handler->getClass(), $handler->getMethod());
} }
@@ -214,24 +214,24 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
{ {
$parent = $this->methods->get($method); $parent = $this->methods->get($method);
if ($parent === null) { if ($parent === null) {
return $this->default->get('handler'); return $this->default->get(':_handler');
} }
if ($method === 'OPTIONS') { if ($method === 'OPTIONS') {
$path = '/*'; $path = '/*';
} }
$lists = str_split($path, 4); $lists = str_split($path, 4);
foreach ($lists as $list) { foreach ($lists as $item) {
$parent = $parent->get($list); $parent = $parent->get($item);
if ($parent === null) { if ($parent === null) {
return $this->default->get('handler'); return $this->default->get(':_handler');
} }
} }
// /** @var HashMap $parent */ // /** @var HashMap $parent */
// $parent = $parent->get($path, $this->default); // $parent = $parent->get($path, $this->default);
return $parent->get('handler'); return $parent->get(':_handler');
} }