upgraded dependencies
This commit is contained in:
@@ -13,15 +13,12 @@ namespace Symfony\Component\EventDispatcher\Debug;
|
||||
|
||||
use Psr\EventDispatcher\StoppableEventInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
|
||||
use Symfony\Component\EventDispatcher\LegacyEventProxy;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
use Symfony\Contracts\EventDispatcher\Event as ContractsEvent;
|
||||
use Symfony\Contracts\Service\ResetInterface;
|
||||
|
||||
/**
|
||||
* Collects some data about event listeners.
|
||||
@@ -30,11 +27,14 @@ use Symfony\Contracts\EventDispatcher\Event as ContractsEvent;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterface
|
||||
{
|
||||
protected $logger;
|
||||
protected $stopwatch;
|
||||
|
||||
/**
|
||||
* @var \SplObjectStorage<WrappedListener, array{string, string}>
|
||||
*/
|
||||
private $callStack;
|
||||
private $dispatcher;
|
||||
private $wrappedListeners;
|
||||
@@ -44,7 +44,7 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
|
||||
public function __construct(EventDispatcherInterface $dispatcher, Stopwatch $stopwatch, LoggerInterface $logger = null, RequestStack $requestStack = null)
|
||||
{
|
||||
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->stopwatch = $stopwatch;
|
||||
$this->logger = $logger;
|
||||
$this->wrappedListeners = [];
|
||||
@@ -55,7 +55,7 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addListener($eventName, $listener, $priority = 0)
|
||||
public function addListener(string $eventName, $listener, int $priority = 0)
|
||||
{
|
||||
$this->dispatcher->addListener($eventName, $listener, $priority);
|
||||
}
|
||||
@@ -71,7 +71,7 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function removeListener($eventName, $listener)
|
||||
public function removeListener(string $eventName, $listener)
|
||||
{
|
||||
if (isset($this->wrappedListeners[$eventName])) {
|
||||
foreach ($this->wrappedListeners[$eventName] as $index => $wrappedListener) {
|
||||
@@ -97,7 +97,7 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getListeners($eventName = null)
|
||||
public function getListeners(string $eventName = null)
|
||||
{
|
||||
return $this->dispatcher->getListeners($eventName);
|
||||
}
|
||||
@@ -105,7 +105,7 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getListenerPriority($eventName, $listener)
|
||||
public function getListenerPriority(string $eventName, $listener)
|
||||
{
|
||||
// we might have wrapped listeners for the event (if called while dispatching)
|
||||
// in that case get the priority by wrapper
|
||||
@@ -123,39 +123,25 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasListeners($eventName = null)
|
||||
public function hasListeners(string $eventName = null)
|
||||
{
|
||||
return $this->dispatcher->hasListeners($eventName);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param string|null $eventName
|
||||
*/
|
||||
public function dispatch($event/* , string $eventName = null */)
|
||||
public function dispatch(object $event, string $eventName = null): object
|
||||
{
|
||||
$eventName = $eventName ?? \get_class($event);
|
||||
|
||||
if (null === $this->callStack) {
|
||||
$this->callStack = new \SplObjectStorage();
|
||||
}
|
||||
|
||||
$currentRequestHash = $this->currentRequestHash = $this->requestStack && ($request = $this->requestStack->getCurrentRequest()) ? spl_object_hash($request) : '';
|
||||
$eventName = 1 < \func_num_args() ? func_get_arg(1) : null;
|
||||
|
||||
if (\is_object($event)) {
|
||||
$eventName = $eventName ?? \get_class($event);
|
||||
} else {
|
||||
@trigger_error(sprintf('Calling the "%s::dispatch()" method with the event name as first argument is deprecated since Symfony 4.3, pass it second and provide the event object first instead.', EventDispatcherInterface::class), \E_USER_DEPRECATED);
|
||||
$swap = $event;
|
||||
$event = $eventName ?? new Event();
|
||||
$eventName = $swap;
|
||||
|
||||
if (!$event instanceof Event) {
|
||||
throw new \TypeError(sprintf('Argument 1 passed to "%s::dispatch()" must be an instance of "%s", "%s" given.', EventDispatcherInterface::class, Event::class, \is_object($event) ? \get_class($event) : \gettype($event)));
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $this->logger && ($event instanceof Event || $event instanceof ContractsEvent || $event instanceof StoppableEventInterface) && $event->isPropagationStopped()) {
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -183,17 +169,15 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param Request|null $request The request to get listeners for
|
||||
* @return array
|
||||
*/
|
||||
public function getCalledListeners(/* Request $request = null */)
|
||||
public function getCalledListeners(Request $request = null)
|
||||
{
|
||||
if (null === $this->callStack) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$hash = 1 <= \func_num_args() && null !== ($request = func_get_arg(0)) ? spl_object_hash($request) : null;
|
||||
$hash = $request ? spl_object_hash($request) : null;
|
||||
$called = [];
|
||||
foreach ($this->callStack as $listener) {
|
||||
[$eventName, $requestHash] = $this->callStack->getInfo();
|
||||
@@ -206,11 +190,9 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param Request|null $request The request to get listeners for
|
||||
* @return array
|
||||
*/
|
||||
public function getNotCalledListeners(/* Request $request = null */)
|
||||
public function getNotCalledListeners(Request $request = null)
|
||||
{
|
||||
try {
|
||||
$allListeners = $this->getListeners();
|
||||
@@ -223,7 +205,7 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
return [];
|
||||
}
|
||||
|
||||
$hash = 1 <= \func_num_args() && null !== ($request = func_get_arg(0)) ? spl_object_hash($request) : null;
|
||||
$hash = $request ? spl_object_hash($request) : null;
|
||||
$calledListeners = [];
|
||||
|
||||
if (null !== $this->callStack) {
|
||||
@@ -253,12 +235,9 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
return $notCalled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request|null $request The request to get orphaned events for
|
||||
*/
|
||||
public function getOrphanedEvents(/* Request $request = null */): array
|
||||
public function getOrphanedEvents(Request $request = null): array
|
||||
{
|
||||
if (1 <= \func_num_args() && null !== $request = func_get_arg(0)) {
|
||||
if ($request) {
|
||||
return $this->orphanedEvents[spl_object_hash($request)] ?? [];
|
||||
}
|
||||
|
||||
@@ -284,46 +263,26 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $arguments)
|
||||
public function __call(string $method, array $arguments)
|
||||
{
|
||||
return $this->dispatcher->{$method}(...$arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before dispatching the event.
|
||||
*
|
||||
* @param object $event
|
||||
*/
|
||||
protected function beforeDispatch(string $eventName, $event)
|
||||
protected function beforeDispatch(string $eventName, object $event)
|
||||
{
|
||||
$this->preDispatch($eventName, $event instanceof Event ? $event : new LegacyEventProxy($event));
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after dispatching the event.
|
||||
*
|
||||
* @param object $event
|
||||
*/
|
||||
protected function afterDispatch(string $eventName, $event)
|
||||
{
|
||||
$this->postDispatch($eventName, $event instanceof Event ? $event : new LegacyEventProxy($event));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since Symfony 4.3, will be removed in 5.0, use beforeDispatch instead
|
||||
*/
|
||||
protected function preDispatch($eventName, Event $event)
|
||||
protected function afterDispatch(string $eventName, object $event)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since Symfony 4.3, will be removed in 5.0, use afterDispatch instead
|
||||
*/
|
||||
protected function postDispatch($eventName, Event $event)
|
||||
{
|
||||
}
|
||||
|
||||
private function preProcess(string $eventName)
|
||||
private function preProcess(string $eventName): void
|
||||
{
|
||||
if (!$this->dispatcher->hasListeners($eventName)) {
|
||||
$this->orphanedEvents[$this->currentRequestHash][] = $eventName;
|
||||
@@ -341,7 +300,7 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
}
|
||||
}
|
||||
|
||||
private function postProcess(string $eventName)
|
||||
private function postProcess(string $eventName): void
|
||||
{
|
||||
unset($this->wrappedListeners[$eventName]);
|
||||
$skipped = false;
|
||||
|
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\EventDispatcher\Debug;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Contracts\Service\ResetInterface;
|
||||
|
||||
/**
|
||||
* @deprecated since Symfony 4.1
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
interface TraceableEventDispatcherInterface extends EventDispatcherInterface, ResetInterface
|
||||
{
|
||||
/**
|
||||
* Gets the called listeners.
|
||||
*
|
||||
* @param Request|null $request The request to get listeners for
|
||||
*
|
||||
* @return array An array of called listeners
|
||||
*/
|
||||
public function getCalledListeners(/* Request $request = null */);
|
||||
|
||||
/**
|
||||
* Gets the not called listeners.
|
||||
*
|
||||
* @param Request|null $request The request to get listeners for
|
||||
*
|
||||
* @return array An array of not called listeners
|
||||
*/
|
||||
public function getNotCalledListeners(/* Request $request = null */);
|
||||
}
|
@@ -12,19 +12,14 @@
|
||||
namespace Symfony\Component\EventDispatcher\Debug;
|
||||
|
||||
use Psr\EventDispatcher\StoppableEventInterface;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\LegacyEventProxy;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
use Symfony\Component\VarDumper\Caster\ClassStub;
|
||||
use Symfony\Contracts\EventDispatcher\Event as ContractsEvent;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @final since Symfony 4.3: the "Event" type-hint on __invoke() will be replaced by "object" in 5.0
|
||||
*/
|
||||
class WrappedListener
|
||||
final class WrappedListener
|
||||
{
|
||||
private $listener;
|
||||
private $optimizedListener;
|
||||
@@ -48,13 +43,13 @@ class WrappedListener
|
||||
$this->stoppedPropagation = false;
|
||||
|
||||
if (\is_array($listener)) {
|
||||
$this->name = \is_object($listener[0]) ? \get_class($listener[0]) : $listener[0];
|
||||
$this->name = \is_object($listener[0]) ? get_debug_type($listener[0]) : $listener[0];
|
||||
$this->pretty = $this->name.'::'.$listener[1];
|
||||
} elseif ($listener instanceof \Closure) {
|
||||
$r = new \ReflectionFunction($listener);
|
||||
if (str_contains($r->name, '{closure}')) {
|
||||
$this->pretty = $this->name = 'closure';
|
||||
} elseif ($class = $r->getClosureScopeClass()) {
|
||||
} elseif ($class = \PHP_VERSION_ID >= 80111 ? $r->getClosureCalledClass() : $r->getClosureScopeClass()) {
|
||||
$this->name = $class->name;
|
||||
$this->pretty = $this->name.'::'.$r->name;
|
||||
} else {
|
||||
@@ -63,7 +58,7 @@ class WrappedListener
|
||||
} elseif (\is_string($listener)) {
|
||||
$this->pretty = $this->name = $listener;
|
||||
} else {
|
||||
$this->name = \get_class($listener);
|
||||
$this->name = get_debug_type($listener);
|
||||
$this->pretty = $this->name.'::__invoke';
|
||||
}
|
||||
|
||||
@@ -81,22 +76,22 @@ class WrappedListener
|
||||
return $this->listener;
|
||||
}
|
||||
|
||||
public function wasCalled()
|
||||
public function wasCalled(): bool
|
||||
{
|
||||
return $this->called;
|
||||
}
|
||||
|
||||
public function stoppedPropagation()
|
||||
public function stoppedPropagation(): bool
|
||||
{
|
||||
return $this->stoppedPropagation;
|
||||
}
|
||||
|
||||
public function getPretty()
|
||||
public function getPretty(): string
|
||||
{
|
||||
return $this->pretty;
|
||||
}
|
||||
|
||||
public function getInfo($eventName)
|
||||
public function getInfo(string $eventName): array
|
||||
{
|
||||
if (null === $this->stub) {
|
||||
$this->stub = self::$hasClassStub ? new ClassStub($this->pretty.'()', $this->listener) : $this->pretty.'()';
|
||||
@@ -110,12 +105,8 @@ class WrappedListener
|
||||
];
|
||||
}
|
||||
|
||||
public function __invoke(Event $event, $eventName, EventDispatcherInterface $dispatcher)
|
||||
public function __invoke(object $event, string $eventName, EventDispatcherInterface $dispatcher): void
|
||||
{
|
||||
if ($event instanceof LegacyEventProxy) {
|
||||
$event = $event->getEvent();
|
||||
}
|
||||
|
||||
$dispatcher = $this->dispatcher ?: $dispatcher;
|
||||
|
||||
$this->called = true;
|
||||
@@ -129,7 +120,7 @@ class WrappedListener
|
||||
$e->stop();
|
||||
}
|
||||
|
||||
if (($event instanceof Event || $event instanceof ContractsEvent || $event instanceof StoppableEventInterface) && $event->isPropagationStopped()) {
|
||||
if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
|
||||
$this->stoppedPropagation = true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user