Files
kiri-core/Annotation/Event.php
T

44 lines
674 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
}
/**
* @param array $handler
2021-04-27 15:57:50 +08:00
* @return bool
2021-02-22 17:44:24 +08:00
* @throws Exception
*/
2021-04-27 15:57:50 +08:00
public function execute(array $handler): bool
2021-02-22 17:44:24 +08:00
{
// TODO: Implement execute() method.
2021-04-27 15:57:50 +08:00
SEvent::on($this->name, $handler, $this->params);
return true;
2021-02-09 11:13:43 +08:00
}
}