From 3541c79b27b5c05aaa9b988aac047cffb22dfaf0 Mon Sep 17 00:00:00 2001 From: whwyy Date: Tue, 12 Dec 2023 16:37:38 +0800 Subject: [PATCH] eee --- src/RouterCollector.php | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/RouterCollector.php b/src/RouterCollector.php index 6a4c8e8..eecb5d4 100644 --- a/src/RouterCollector.php +++ b/src/RouterCollector.php @@ -85,8 +85,7 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate { $found = di(NotFoundController::class); - $reflection = new ReflectionMethod($found, 'fail'); - + $reflection = new ReflectionMethod($found, 'fail'); $this->found = new Handler([$found, 'fail'], [], $reflection->getReturnType()); } @@ -153,11 +152,6 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate } else if (is_string($closure)) { $closure = explode('@', $closure); } - $this->dump[] = [ - 'method' => $value, - 'path' => $route, - 'callback' => $closure instanceof Closure ? 'Closure' : $closure - ]; $this->register($route, $value, $handler); } } 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 ControllerInterpreter $interpreter