Files
kiri-event/EventDispatch.php
T

41 lines
861 B
PHP
Raw Permalink Normal View History

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-02-23 16:32:08 +08:00
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
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
2022-02-23 16:32:08 +08:00
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
2022-01-09 13:57:10 +08:00
*/
public function dispatch(object $event): object
{
2022-01-20 19:04:16 +08:00
$lists = $this->getEventProvider()->getListenersForEvent($event);
2022-01-09 13:57:10 +08:00
foreach ($lists as $listener) {
/** @var Struct $list */
$listener($event);
if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
break;
}
}
return $event;
}
}