Files
kiri-event/EventListener.php
T
2024-10-09 16:01:22 +08:00

36 lines
655 B
PHP

<?php
namespace Kiri\Events;
use Exception;
use Kiri\Di\Interface\InjectTargetInterface;
#[\Attribute]
readonly class EventListener implements InjectTargetInterface
{
/**
* @param string $event
* @throws Exception
*/
public function __construct(public string $event)
{
}
/**
* @param string $class
* @return void
* @throws Exception
*/
public function dispatch(string $class): void
{
// TODO: Implement dispatch() method.
$target = \Kiri::getDi()->getReflectionClass($class)->newInstanceWithoutConstructor();
on($this->event, [$target, "onHandler"]);
}
}