🔧
This commit is contained in:
@@ -30,25 +30,20 @@ use Symfony\Contracts\Service\ResetInterface;
|
||||
*/
|
||||
class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterface
|
||||
{
|
||||
protected ?LoggerInterface $logger;
|
||||
protected Stopwatch $stopwatch;
|
||||
|
||||
/**
|
||||
* @var \SplObjectStorage<WrappedListener, array{string, string}>|null
|
||||
*/
|
||||
private ?\SplObjectStorage $callStack = null;
|
||||
private EventDispatcherInterface $dispatcher;
|
||||
private array $wrappedListeners = [];
|
||||
private array $orphanedEvents = [];
|
||||
private ?RequestStack $requestStack;
|
||||
private string $currentRequestHash = '';
|
||||
|
||||
public function __construct(EventDispatcherInterface $dispatcher, Stopwatch $stopwatch, LoggerInterface $logger = null, RequestStack $requestStack = null)
|
||||
{
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->stopwatch = $stopwatch;
|
||||
$this->logger = $logger;
|
||||
$this->requestStack = $requestStack;
|
||||
public function __construct(
|
||||
private EventDispatcherInterface $dispatcher,
|
||||
protected Stopwatch $stopwatch,
|
||||
protected ?LoggerInterface $logger = null,
|
||||
private ?RequestStack $requestStack = null,
|
||||
) {
|
||||
}
|
||||
|
||||
public function addListener(string $eventName, callable|array $listener, int $priority = 0): void
|
||||
@@ -81,7 +76,7 @@ class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterfa
|
||||
$this->dispatcher->removeSubscriber($subscriber);
|
||||
}
|
||||
|
||||
public function getListeners(string $eventName = null): array
|
||||
public function getListeners(?string $eventName = null): array
|
||||
{
|
||||
return $this->dispatcher->getListeners($eventName);
|
||||
}
|
||||
@@ -101,12 +96,12 @@ class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterfa
|
||||
return $this->dispatcher->getListenerPriority($eventName, $listener);
|
||||
}
|
||||
|
||||
public function hasListeners(string $eventName = null): bool
|
||||
public function hasListeners(?string $eventName = null): bool
|
||||
{
|
||||
return $this->dispatcher->hasListeners($eventName);
|
||||
}
|
||||
|
||||
public function dispatch(object $event, string $eventName = null): object
|
||||
public function dispatch(object $event, ?string $eventName = null): object
|
||||
{
|
||||
$eventName ??= $event::class;
|
||||
|
||||
@@ -115,7 +110,7 @@ class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterfa
|
||||
$currentRequestHash = $this->currentRequestHash = $this->requestStack && ($request = $this->requestStack->getCurrentRequest()) ? spl_object_hash($request) : '';
|
||||
|
||||
if (null !== $this->logger && $event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
|
||||
$this->logger->debug(sprintf('The "%s" event is already stopped. No listeners have been called.', $eventName));
|
||||
$this->logger->debug(\sprintf('The "%s" event is already stopped. No listeners have been called.', $eventName));
|
||||
}
|
||||
|
||||
$this->preProcess($eventName);
|
||||
@@ -141,7 +136,7 @@ class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterfa
|
||||
return $event;
|
||||
}
|
||||
|
||||
public function getCalledListeners(Request $request = null): array
|
||||
public function getCalledListeners(?Request $request = null): array
|
||||
{
|
||||
if (null === $this->callStack) {
|
||||
return [];
|
||||
@@ -159,7 +154,7 @@ class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterfa
|
||||
return $called;
|
||||
}
|
||||
|
||||
public function getNotCalledListeners(Request $request = null): array
|
||||
public function getNotCalledListeners(?Request $request = null): array
|
||||
{
|
||||
try {
|
||||
$allListeners = $this->dispatcher instanceof EventDispatcher ? $this->getListenersWithPriority() : $this->getListenersWithoutPriority();
|
||||
@@ -201,7 +196,7 @@ class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterfa
|
||||
return $notCalled;
|
||||
}
|
||||
|
||||
public function getOrphanedEvents(Request $request = null): array
|
||||
public function getOrphanedEvents(?Request $request = null): array
|
||||
{
|
||||
if ($request) {
|
||||
return $this->orphanedEvents[spl_object_hash($request)] ?? [];
|
||||
|
||||
Reference in New Issue
Block a user