Files
kiri-core/note/Event.php
T
as2252258@163.com 133ca2c273 111
2021-08-29 04:06:49 +08:00

46 lines
709 B
PHP

<?php
namespace Annotation;
use Exception;
use Kiri\Events\EventProvider;
/**
* Class Event
* @package Annotation
*/
#[\Attribute(\Attribute::TARGET_METHOD)] class Event extends Attribute
{
/**
* Event constructor.
* @param string $name
* @param array $params
*/
public function __construct(string $name, array $params = [])
{
}
/**
* @param mixed $class
* @param mixed|null $method
* @return bool
* @throws Exception
*/
public static function execute(mixed $params, mixed $class, mixed $method = null): bool
{
$pro = di(EventProvider::class);
if (is_string($class)) {
$class = di($class);
}
$pro->on($params->name, [$class, $method]);
return true;
}
}