Files
kiri-core/Annotation/Aspect.php
T

52 lines
966 B
PHP
Raw Normal View History

2021-03-29 02:34:31 +08:00
<?php
namespace Annotation;
2021-03-29 10:05:51 +08:00
use Exception;
2021-03-29 03:09:55 +08:00
use Snowflake\Aop;
use Snowflake\IAspect;
use Snowflake\Snowflake;
defined('ASPECT_ERROR') or define('ASPECT_ERROR', 'Aspect annotation must implement ');
2021-03-29 02:34:31 +08:00
/**
* Class Aspect
* @package Annotation
*/
2021-03-29 03:09:55 +08:00
#[\Attribute(\Attribute::TARGET_METHOD)] class Aspect extends Attribute
2021-03-29 02:34:31 +08:00
{
/**
* Aspect constructor.
2021-03-29 03:09:55 +08:00
* @param string $aspect
2021-03-29 02:34:31 +08:00
*/
2021-03-29 03:09:55 +08:00
public function __construct(public string $aspect)
2021-03-29 02:34:31 +08:00
{
}
2021-03-29 10:05:51 +08:00
/**
* @param array $handler
* @return mixed
* @throws Exception
*/
2021-03-29 02:34:31 +08:00
public function execute(array $handler): mixed
{
2021-03-29 10:05:51 +08:00
// TODO: Change the autogenerated stub
if (!in_array(IAspect::class, class_implements($this->aspect))) {
throw new Exception(ASPECT_ERROR . IAspect::class);
2021-03-29 03:09:55 +08:00
}
/** @var Aop $aop */
$aop = Snowflake::app()->get('aop');
$aop->aop_add($handler, $this->aspect);
2021-03-29 10:05:51 +08:00
return parent::execute($handler);
2021-03-29 02:34:31 +08:00
}
}