Files
kiri-core/Annotation/Event.php
T
2021-02-22 17:44:24 +08:00

45 lines
746 B
PHP

<?php
namespace Annotation;
use Exception;
use Snowflake\Exception\ComponentException;
use Snowflake\Snowflake;
/**
* Class Event
* @package Annotation
*/
#[\Attribute(\Attribute::TARGET_METHOD)] class Event implements IAnnotation
{
/**
* Event constructor.
* @param string $name
* @param array $params
*/
public function __construct(public string $name, public array $params = [])
{
}
/**
* @param array $handler
* @return \Snowflake\Event
* @throws ComponentException
* @throws Exception
*/
public function execute(array $handler): \Snowflake\Event
{
// TODO: Implement execute() method.
$event = Snowflake::app()->getEvent();
$event->on($this->name, $handler, $this->params);
return $event;
}
}