2021-02-09 11:13:43 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Annotation;
|
|
|
|
|
|
|
|
|
|
|
2021-02-22 17:44:24 +08:00
|
|
|
use Exception;
|
2021-08-11 01:04:57 +08:00
|
|
|
use Kiri\Exception\ComponentException;
|
|
|
|
|
use Kiri\Kiri;
|
|
|
|
|
use Kiri\Event as SEvent;
|
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
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(public string $name, public array $params = [])
|
|
|
|
|
{
|
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-07-12 17:17:36 +08:00
|
|
|
public function execute(mixed $class, mixed $method = null): bool
|
|
|
|
|
{
|
2021-02-22 17:44:24 +08:00
|
|
|
// TODO: Implement execute() method.
|
2021-08-03 18:20:44 +08:00
|
|
|
SEvent::on($this->name, [$class, $method]);
|
2021-04-27 15:57:50 +08:00
|
|
|
return true;
|
2021-02-09 11:13:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|