改名
This commit is contained in:
+10
-7
@@ -4,6 +4,7 @@
|
|||||||
namespace Annotation;
|
namespace Annotation;
|
||||||
|
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use Snowflake\Aop;
|
use Snowflake\Aop;
|
||||||
use Snowflake\IAspect;
|
use Snowflake\IAspect;
|
||||||
use Snowflake\Snowflake;
|
use Snowflake\Snowflake;
|
||||||
@@ -27,21 +28,23 @@ defined('ASPECT_ERROR') or define('ASPECT_ERROR', 'Aspect annotation must implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $handler
|
* @param array $handler
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
* @throws Exception
|
||||||
|
*/
|
||||||
public function execute(array $handler): mixed
|
public function execute(array $handler): mixed
|
||||||
{
|
{
|
||||||
if (!in_array(IAspect::class, class_implements($this->aspect))) {
|
// TODO: Change the autogenerated stub
|
||||||
throw new \Exception(ASPECT_ERROR . IAspect::class);
|
if (!in_array(IAspect::class, class_implements($this->aspect))) {
|
||||||
|
throw new Exception(ASPECT_ERROR . IAspect::class);
|
||||||
}
|
}
|
||||||
/** @var Aop $aop */
|
/** @var Aop $aop */
|
||||||
$aop = Snowflake::app()->get('aop');
|
$aop = Snowflake::app()->get('aop');
|
||||||
|
|
||||||
$aop->aop_add($handler, $this->aspect);
|
$aop->aop_add($handler, $this->aspect);
|
||||||
|
|
||||||
return parent::execute($handler); // TODO: Change the autogenerated stub
|
return parent::execute($handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+15
-10
@@ -4,7 +4,10 @@
|
|||||||
namespace Snowflake;
|
namespace Snowflake;
|
||||||
|
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use ReflectionException;
|
||||||
use Snowflake\Abstracts\Component;
|
use Snowflake\Abstracts\Component;
|
||||||
|
use Snowflake\Exception\NotFindClassException;
|
||||||
|
|
||||||
defined('ASPECT_ERROR') or define('ASPECT_ERROR', 'Aspect annotation must implement ');
|
defined('ASPECT_ERROR') or define('ASPECT_ERROR', 'Aspect annotation must implement ');
|
||||||
|
|
||||||
@@ -20,10 +23,10 @@ class Aop extends Component
|
|||||||
private array $_aop = [];
|
private array $_aop = [];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $className
|
* @param array $handler
|
||||||
* @param null $method
|
* @param string $aspect
|
||||||
*/
|
*/
|
||||||
public function aop_add(array $handler, string $aspect)
|
public function aop_add(array $handler, string $aspect)
|
||||||
{
|
{
|
||||||
[$class, $method] = $handler;
|
[$class, $method] = $handler;
|
||||||
@@ -35,11 +38,13 @@ class Aop extends Component
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return mixed|void
|
* @return mixed
|
||||||
* @throws \ReflectionException
|
* @throws NotFindClassException
|
||||||
*/
|
* @throws ReflectionException
|
||||||
final public function dispatch()
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
final public function dispatch(): mixed
|
||||||
{
|
{
|
||||||
$get_args = func_get_args();
|
$get_args = func_get_args();
|
||||||
if (($close = array_shift($get_args)) instanceof \Closure) {
|
if (($close = array_shift($get_args)) instanceof \Closure) {
|
||||||
@@ -53,7 +58,7 @@ class Aop extends Component
|
|||||||
|
|
||||||
$reflect = Snowflake::getDi()->getReflect($this->_aop[$aopName]);
|
$reflect = Snowflake::getDi()->getReflect($this->_aop[$aopName]);
|
||||||
if (!$reflect->isInstantiable() || !$reflect->hasMethod('invoke')) {
|
if (!$reflect->isInstantiable() || !$reflect->hasMethod('invoke')) {
|
||||||
throw new \Exception(ASPECT_ERROR . IAspect::class);
|
throw new Exception(ASPECT_ERROR . IAspect::class);
|
||||||
}
|
}
|
||||||
$method = $reflect->getMethod('invoke');
|
$method = $reflect->getMethod('invoke');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user