_aop[$alias])) { $this->_aop[$alias] = []; } if (in_array($aspect, $this->_aop[$alias])) { return; } $this->_aop[$alias][] = $aspect; } /** * @return mixed * @throws NotFindClassException * @throws ReflectionException * @throws Exception */ final public function dispatch($handler, ...$params): mixed { if ($handler instanceof \Closure) { return call_user_func($handler, ...$params); } $aopName = get_class($handler) . '::' . $handler; if (!isset($this->_aop[$aopName])) { if (!method_exists($handler[0], $handler[1])) { return response()->close(404); } return call_user_func($handler, ...$params); } $reflect = Snowflake::getDi()->getReflect(current($this->_aop[$aopName])); if (!$reflect->isInstantiable() || !$reflect->hasMethod('invoke')) { throw new Exception(ASPECT_ERROR . IAspect::class); } $method = $reflect->getMethod('invoke'); return $method->invokeArgs($reflect->newInstance($handler), $params); } }