2021-08-25 16:07:04 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Kiri\Events;
|
|
|
|
|
|
2021-12-03 15:44:06 +08:00
|
|
|
use Kiri\Abstracts\Component;
|
2021-12-08 11:32:32 +08:00
|
|
|
use Kiri\Kiri;
|
2021-08-25 16:07:04 +08:00
|
|
|
use Psr\EventDispatcher\EventDispatcherInterface;
|
|
|
|
|
use Psr\EventDispatcher\StoppableEventInterface;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
2021-12-03 15:44:06 +08:00
|
|
|
class EventDispatch extends Component implements EventDispatcherInterface
|
2021-08-25 16:07:04 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param object $event
|
|
|
|
|
* @return object
|
2021-12-08 11:32:32 +08:00
|
|
|
* @throws \ReflectionException
|
2021-08-25 16:07:04 +08:00
|
|
|
*/
|
|
|
|
|
public function dispatch(object $event): object
|
|
|
|
|
{
|
2022-01-04 16:04:22 +08:00
|
|
|
$lists = $this->eventProvider->getListenersForEvent($event);
|
2021-08-25 16:07:04 +08:00
|
|
|
foreach ($lists as $listener) {
|
|
|
|
|
/** @var Struct $list */
|
|
|
|
|
$listener($event);
|
|
|
|
|
if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $event;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|