This commit is contained in:
2023-04-16 17:23:37 +08:00
parent 740e8c5c94
commit 347f4fa0ae
+11 -9
View File
@@ -52,12 +52,11 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
/** /**
* @param RequestMethod[] $method * @param array $method
* @param string $route * @param string $route
* @param string|Closure $closure * @param string|array|Closure $closure
* @throws
*/ */
public function addRoute(array $method, string $route, string|Closure $closure) public function addRoute(array $method, string $route, string|array|Closure $closure)
{ {
try { try {
$route = $this->_splicing_routing($route); $route = $this->_splicing_routing($route);
@@ -80,17 +79,20 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
/** /**
* @param string $closure * @param string|array $closure
* @param ControllerInterpreter $interpreter * @param ControllerInterpreter $interpreter
* @return Handler * @return Handler
* @throws ReflectionException * @throws ReflectionException
*/ */
private function resolve(string $closure, ControllerInterpreter $interpreter): Handler private function resolve(string|array $closure, ControllerInterpreter $interpreter): Handler
{ {
[$className, $method] = explode('@', $closure); if (is_array($closure)) {
[$class, $method] = $closure;
$class = Kiri::getDi()->get($this->resetName($className)); } else {
[$className, $method] = explode('@', $closure);
$class = Kiri::getDi()->get($this->resetName($className));
}
return $interpreter->addRouteByString($class, $method); return $interpreter->addRouteByString($class, $method);
} }