qqq
This commit is contained in:
+14
-15
@@ -10,6 +10,7 @@ use Psr\Container\ContainerExceptionInterface;
|
|||||||
use Psr\Container\NotFoundExceptionInterface;
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
use Psr\EventDispatcher\EventDispatcherInterface;
|
use Psr\EventDispatcher\EventDispatcherInterface;
|
||||||
use Psr\EventDispatcher\StoppableEventInterface;
|
use Psr\EventDispatcher\StoppableEventInterface;
|
||||||
|
use ReflectionException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,26 +24,24 @@ class EventDispatch extends Component implements EventDispatcherInterface
|
|||||||
* @param object $event
|
* @param object $event
|
||||||
* @return object
|
* @return object
|
||||||
* @throws ContainerExceptionInterface
|
* @throws ContainerExceptionInterface
|
||||||
* @throws NotFoundExceptionInterface|\ReflectionException
|
* @throws NotFoundExceptionInterface|ReflectionException
|
||||||
*/
|
*/
|
||||||
public function dispatch(object $event): object
|
public function dispatch(object $event): object
|
||||||
{
|
{
|
||||||
$lists = Kiri::getDi()->get(EventProvider::class)->getListenersForEvent($event);
|
$lists = make(EventProvider::class)->getListenersForEvent($event);
|
||||||
if (!$lists->valid()) {
|
if ($lists->isEmpty()) {
|
||||||
return $event;
|
return $event;
|
||||||
}
|
}
|
||||||
$lists->top();
|
foreach ($lists as $item) {
|
||||||
while ($lists->valid()) {
|
try {
|
||||||
try {
|
call_user_func($item, $event);
|
||||||
call_user_func($lists->current(), $event);
|
} catch (\Throwable $exception) {
|
||||||
} catch (\Throwable $exception) {
|
error($exception);
|
||||||
error($exception);
|
}
|
||||||
}
|
if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
|
||||||
if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
|
break;
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
$lists->next();
|
|
||||||
}
|
|
||||||
return $event;
|
return $event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user