This commit is contained in:
2023-12-12 16:37:38 +08:00
parent 2030841322
commit 3541c79b27
+21 -7
View File
@@ -85,8 +85,7 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
{ {
$found = di(NotFoundController::class); $found = di(NotFoundController::class);
$reflection = new ReflectionMethod($found, 'fail'); $reflection = new ReflectionMethod($found, 'fail');
$this->found = new Handler([$found, 'fail'], [], $reflection->getReturnType()); $this->found = new Handler([$found, 'fail'], [], $reflection->getReturnType());
} }
@@ -153,11 +152,6 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
} else if (is_string($closure)) { } else if (is_string($closure)) {
$closure = explode('@', $closure); $closure = explode('@', $closure);
} }
$this->dump[] = [
'method' => $value,
'path' => $route,
'callback' => $closure instanceof Closure ? 'Closure' : $closure
];
$this->register($route, $value, $handler); $this->register($route, $value, $handler);
} }
} catch (Throwable $throwable) { } catch (Throwable $throwable) {
@@ -166,6 +160,26 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
} }
/**
* @return array
*/
public function dump(): array
{
$array = [];
foreach ($this->methods as $methodPath => $handler) {
[$path, $method] = explode('_', $methodPath);
$controller = $handler->isClosure() ? '\Closure' : $handler->getClass() . '::' . $handler->getMethod();
$array[] = [
'path' => $path,
'method' => $method,
'handler' => $controller
];
}
return $array;
}
/** /**
* @param string|array $closure * @param string|array $closure
* @param ControllerInterpreter $interpreter * @param ControllerInterpreter $interpreter