Files
kiri-core/note/Event.php
T

46 lines
709 B
PHP
Raw Normal View History

2021-02-09 11:13:43 +08:00
<?php
namespace Annotation;
2021-02-22 17:44:24 +08:00
use Exception;
2021-08-13 14:58:58 +08:00
use Kiri\Events\EventProvider;
2021-02-09 11:13:43 +08:00
/**
* Class Event
* @package Annotation
*/
2021-03-03 18:35:04 +08:00
#[\Attribute(\Attribute::TARGET_METHOD)] class Event extends Attribute
2021-02-09 11:13:43 +08:00
{
/**
* Event constructor.
* @param string $name
* @param array $params
*/
2021-08-29 04:06:49 +08:00
public function __construct(string $name, array $params = [])
2021-02-09 11:13:43 +08:00
{
2021-02-22 17:44:24 +08:00
}
/**
2021-07-12 17:17:36 +08:00
* @param mixed $class
* @param mixed|null $method
2021-04-27 15:57:50 +08:00
* @return bool
2021-02-22 17:44:24 +08:00
* @throws Exception
*/
2021-08-29 04:06:49 +08:00
public static function execute(mixed $params, mixed $class, mixed $method = null): bool
2021-08-13 14:58:58 +08:00
{
$pro = di(EventProvider::class);
2021-08-13 15:22:11 +08:00
if (is_string($class)) {
$class = di($class);
}
2021-08-29 04:06:49 +08:00
$pro->on($params->name, [$class, $method]);
2021-04-27 15:57:50 +08:00
return true;
2021-02-09 11:13:43 +08:00
}
}