modify
This commit is contained in:
+29
-6
@@ -47,20 +47,29 @@ class Aop extends Component
|
||||
* @throws ReflectionException
|
||||
* @throws Exception
|
||||
*/
|
||||
final public function dispatch($handler, ...$params): mixed
|
||||
final public function dispatch($handler, $params): mixed
|
||||
{
|
||||
if ($handler instanceof \Closure) {
|
||||
return call_user_func($handler, ...$params);
|
||||
}
|
||||
|
||||
$aopName = get_class($handler) . '::' . $handler;
|
||||
$aopName = get_class($handler[0]) . '::' . $handler[1];
|
||||
if (!isset($this->_aop[$aopName])) {
|
||||
if (!method_exists($handler[0], $handler[1])) {
|
||||
return response()->close(404);
|
||||
return $this->notFound($handler, $params);
|
||||
}
|
||||
return call_user_func($handler, ...$params);
|
||||
return $this->invoke($handler, $params, $aopName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $handler
|
||||
* @param $params
|
||||
* @param $aopName
|
||||
* @return mixed
|
||||
* @throws \ReflectionException
|
||||
* @throws \Snowflake\Exception\NotFindClassException
|
||||
*/
|
||||
private function invoke($handler, $params, $aopName)
|
||||
{
|
||||
$reflect = Snowflake::getDi()->getReflect(current($this->_aop[$aopName]));
|
||||
if (!$reflect->isInstantiable() || !$reflect->hasMethod('invoke')) {
|
||||
throw new Exception(ASPECT_ERROR . IAspect::class);
|
||||
@@ -71,4 +80,18 @@ class Aop extends Component
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $handler
|
||||
* @param $params
|
||||
* @return false|mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function notFound($handler, $params)
|
||||
{
|
||||
if (!method_exists($handler[0], $handler[1])) {
|
||||
return response()->close(404);
|
||||
}
|
||||
return call_user_func($handler, ...$params);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user