modify plugin name

This commit is contained in:
2022-06-22 19:16:08 +08:00
parent acce084300
commit af647afb93
2 changed files with 14 additions and 10 deletions
+6 -4
View File
@@ -36,17 +36,19 @@ class EventDispatch extends Component implements EventDispatcherInterface
*/
public function dispatch(object $event): object
{
/** @var \SplPriorityQueue $lists */
$lists = $this->eventProvider->getListenersForEvent($event);
foreach ($lists as $listener) {
/** @var Struct $list */
$lists->top();
while ($lists->valid()) {
try {
$listener($event);
}catch (\Throwable $exception) {
call_user_func($lists->current(), $event);
} catch (\Throwable $exception) {
$this->logger->error($exception->getMessage(), [$exception]);
}
if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
break;
}
$lists->next();
}
return $event;
}
+5 -3
View File
@@ -4,6 +4,7 @@ namespace Kiri\Events;
use Psr\EventDispatcher\ListenerProviderInterface;
use SplPriorityQueue;
/**
*
@@ -17,11 +18,12 @@ class EventProvider implements ListenerProviderInterface
/**
* @param object $event
* @return iterable
* @return SplPriorityQueue
*/
public function getListenersForEvent(object $event): iterable
public function getListenersForEvent(object $event): SplPriorityQueue
{
$queue = new \SplPriorityQueue();
$queue = new SplPriorityQueue();
$queue->setExtractFlags(SplPriorityQueue::EXTR_PRIORITY);
// TODO: Implement getListenersForEvent() method.
foreach ($this->_listeners[get_class($event)] ?? [] as $listener) {
$queue->insert($listener->listener, $listener->priority);