This commit is contained in:
2021-04-21 10:49:16 +08:00
parent bc6e4afe12
commit e9ba5ced39
+24 -6
View File
@@ -338,20 +338,38 @@ class Router extends HttpService implements RouterInterface
$array = [];
foreach ($middleware as $value) {
if (is_string($value)) {
$value = Snowflake::createObject($value);
if (!($value instanceof Middleware)) {
continue;
if (is_array($value)) {
foreach ($value as $item) {
$array[] = $this->getMiddlewareInstance($item);
}
$array[] = [$value, 'onHandler'];
} else {
$array[] = $value;
$array[] = $this->getMiddlewareInstance($value);
}
}
return $array;
}
/**
* @param $value
* @return Closure|array|null
* @throws NotFindClassException
* @throws ReflectionException
*/
private function getMiddlewareInstance($value): null|Closure|array
{
if (is_string($value)) {
$value = Snowflake::createObject($value);
if (!($value instanceof Middleware)) {
return null;
}
return [$value, 'onHandler'];
} else {
return $value;
}
}
/**
* @param $method
* @return array