Files
kiri-core/Annotation/Event.php
T

45 lines
722 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-02-09 11:13:43 +08:00
use Snowflake\Exception\ComponentException;
use Snowflake\Snowflake;
2021-04-27 15:57:50 +08:00
use Snowflake\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
}
}