This commit is contained in:
2021-08-24 18:24:46 +08:00
parent 575f4b8520
commit 24c93edf2b
110 changed files with 5 additions and 6 deletions
+45
View File
@@ -0,0 +1,45 @@
<?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(public string $name, public array $params = [])
{
}
/**
* @param mixed $class
* @param mixed|null $method
* @return bool
* @throws Exception
*/
public function execute(mixed $class, mixed $method = null): bool
{
$pro = di(EventProvider::class);
if (is_string($class)) {
$class = di($class);
}
$pro->on($this->name, [$class, $method]);
return true;
}
}