From 347f4fa0aec6987c55710e191be49e51c301fbfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Sun, 16 Apr 2023 17:23:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/RouterCollector.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/RouterCollector.php b/src/RouterCollector.php index e8c7413..b73c2da 100644 --- a/src/RouterCollector.php +++ b/src/RouterCollector.php @@ -52,12 +52,11 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate /** - * @param RequestMethod[] $method + * @param array $method * @param string $route - * @param string|Closure $closure - * @throws + * @param string|array|Closure $closure */ - public function addRoute(array $method, string $route, string|Closure $closure) + public function addRoute(array $method, string $route, string|array|Closure $closure) { try { $route = $this->_splicing_routing($route); @@ -80,17 +79,20 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate /** - * @param string $closure + * @param string|array $closure * @param ControllerInterpreter $interpreter * @return Handler * @throws ReflectionException */ - private function resolve(string $closure, ControllerInterpreter $interpreter): Handler + private function resolve(string|array $closure, ControllerInterpreter $interpreter): Handler { - [$className, $method] = explode('@', $closure); - - $class = Kiri::getDi()->get($this->resetName($className)); + if (is_array($closure)) { + [$class, $method] = $closure; + } else { + [$className, $method] = explode('@', $closure); + $class = Kiri::getDi()->get($this->resetName($className)); + } return $interpreter->addRouteByString($class, $method); }