This commit is contained in:
2021-03-29 10:05:51 +08:00
parent db921d1b61
commit 1d6caa62b5
2 changed files with 25 additions and 17 deletions
+5 -2
View File
@@ -4,6 +4,7 @@
namespace Annotation;
use Exception;
use Snowflake\Aop;
use Snowflake\IAspect;
use Snowflake\Snowflake;
@@ -30,18 +31,20 @@ defined('ASPECT_ERROR') or define('ASPECT_ERROR', 'Aspect annotation must implem
/**
* @param array $handler
* @return mixed
* @throws Exception
*/
public function execute(array $handler): mixed
{
// TODO: Change the autogenerated stub
if (!in_array(IAspect::class, class_implements($this->aspect))) {
throw new \Exception(ASPECT_ERROR . IAspect::class);
throw new Exception(ASPECT_ERROR . IAspect::class);
}
/** @var Aop $aop */
$aop = Snowflake::app()->get('aop');
$aop->aop_add($handler, $this->aspect);
return parent::execute($handler); // TODO: Change the autogenerated stub
return parent::execute($handler);
}
+11 -6
View File
@@ -4,7 +4,10 @@
namespace Snowflake;
use Exception;
use ReflectionException;
use Snowflake\Abstracts\Component;
use Snowflake\Exception\NotFindClassException;
defined('ASPECT_ERROR') or define('ASPECT_ERROR', 'Aspect annotation must implement ');
@@ -21,8 +24,8 @@ class Aop extends Component
/**
* @param $className
* @param null $method
* @param array $handler
* @param string $aspect
*/
public function aop_add(array $handler, string $aspect)
{
@@ -36,10 +39,12 @@ class Aop extends Component
/**
* @return mixed|void
* @throws \ReflectionException
* @return mixed
* @throws NotFindClassException
* @throws ReflectionException
* @throws Exception
*/
final public function dispatch()
final public function dispatch(): mixed
{
$get_args = func_get_args();
if (($close = array_shift($get_args)) instanceof \Closure) {
@@ -53,7 +58,7 @@ class Aop extends Component
$reflect = Snowflake::getDi()->getReflect($this->_aop[$aopName]);
if (!$reflect->isInstantiable() || !$reflect->hasMethod('invoke')) {
throw new \Exception(ASPECT_ERROR . IAspect::class);
throw new Exception(ASPECT_ERROR . IAspect::class);
}
$method = $reflect->getMethod('invoke');