modify
This commit is contained in:
+17
-2
@@ -4,18 +4,25 @@
|
||||
namespace Annotation;
|
||||
|
||||
|
||||
use Snowflake\Aop;
|
||||
use Snowflake\IAspect;
|
||||
use Snowflake\Snowflake;
|
||||
|
||||
defined('ASPECT_ERROR') or define('ASPECT_ERROR', 'Aspect annotation must implement ');
|
||||
|
||||
/**
|
||||
* Class Aspect
|
||||
* @package Annotation
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_FUNCTION)] class Aspect extends Attribute
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Aspect extends Attribute
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Aspect constructor.
|
||||
* @param string $aspect
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct(public string $aspect)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -26,6 +33,14 @@ namespace Annotation;
|
||||
*/
|
||||
public function execute(array $handler): mixed
|
||||
{
|
||||
if (!in_array(IAspect::class, class_implements($this->aspect))) {
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user