2022-01-09 13:57:10 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Kiri\Events;
|
|
|
|
|
|
|
|
|
|
use Kiri\Abstracts\Component;
|
2022-01-12 14:10:33 +08:00
|
|
|
use Kiri;
|
2022-01-09 13:57:10 +08:00
|
|
|
use Psr\EventDispatcher\EventDispatcherInterface;
|
|
|
|
|
use Psr\EventDispatcher\StoppableEventInterface;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
class EventDispatch extends Component implements EventDispatcherInterface
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param object $event
|
|
|
|
|
* @return object
|
|
|
|
|
* @throws \ReflectionException
|
|
|
|
|
*/
|
|
|
|
|
public function dispatch(object $event): object
|
|
|
|
|
{
|
|
|
|
|
$lists = $this->eventProvider->getListenersForEvent($event);
|
|
|
|
|
foreach ($lists as $listener) {
|
|
|
|
|
/** @var Struct $list */
|
|
|
|
|
$listener($event);
|
|
|
|
|
if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $event;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|