first commit
This commit is contained in:
		
							
								
								
									
										346
									
								
								vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										346
									
								
								vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,346 @@ | ||||
| <?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 Psr\Log\LoggerInterface; | ||||
| use Symfony\Component\EventDispatcher\Event; | ||||
| use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||||
| use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||||
| use Symfony\Component\Stopwatch\Stopwatch; | ||||
|  | ||||
| /** | ||||
|  * Collects some data about event listeners. | ||||
|  * | ||||
|  * This event dispatcher delegates the dispatching to another one. | ||||
|  * | ||||
|  * @author Fabien Potencier <fabien@symfony.com> | ||||
|  */ | ||||
| class TraceableEventDispatcher implements TraceableEventDispatcherInterface | ||||
| { | ||||
|     protected $logger; | ||||
|     protected $stopwatch; | ||||
|  | ||||
|     private $callStack; | ||||
|     private $dispatcher; | ||||
|     private $wrappedListeners; | ||||
|     private $orphanedEvents; | ||||
|  | ||||
|     public function __construct(EventDispatcherInterface $dispatcher, Stopwatch $stopwatch, LoggerInterface $logger = null) | ||||
|     { | ||||
|         $this->dispatcher = $dispatcher; | ||||
|         $this->stopwatch = $stopwatch; | ||||
|         $this->logger = $logger; | ||||
|         $this->wrappedListeners = []; | ||||
|         $this->orphanedEvents = []; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * {@inheritdoc} | ||||
|      */ | ||||
|     public function addListener($eventName, $listener, $priority = 0) | ||||
|     { | ||||
|         $this->dispatcher->addListener($eventName, $listener, $priority); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * {@inheritdoc} | ||||
|      */ | ||||
|     public function addSubscriber(EventSubscriberInterface $subscriber) | ||||
|     { | ||||
|         $this->dispatcher->addSubscriber($subscriber); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * {@inheritdoc} | ||||
|      */ | ||||
|     public function removeListener($eventName, $listener) | ||||
|     { | ||||
|         if (isset($this->wrappedListeners[$eventName])) { | ||||
|             foreach ($this->wrappedListeners[$eventName] as $index => $wrappedListener) { | ||||
|                 if ($wrappedListener->getWrappedListener() === $listener) { | ||||
|                     $listener = $wrappedListener; | ||||
|                     unset($this->wrappedListeners[$eventName][$index]); | ||||
|                     break; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return $this->dispatcher->removeListener($eventName, $listener); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * {@inheritdoc} | ||||
|      */ | ||||
|     public function removeSubscriber(EventSubscriberInterface $subscriber) | ||||
|     { | ||||
|         return $this->dispatcher->removeSubscriber($subscriber); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * {@inheritdoc} | ||||
|      */ | ||||
|     public function getListeners($eventName = null) | ||||
|     { | ||||
|         return $this->dispatcher->getListeners($eventName); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * {@inheritdoc} | ||||
|      */ | ||||
|     public function getListenerPriority($eventName, $listener) | ||||
|     { | ||||
|         // we might have wrapped listeners for the event (if called while dispatching) | ||||
|         // in that case get the priority by wrapper | ||||
|         if (isset($this->wrappedListeners[$eventName])) { | ||||
|             foreach ($this->wrappedListeners[$eventName] as $index => $wrappedListener) { | ||||
|                 if ($wrappedListener->getWrappedListener() === $listener) { | ||||
|                     return $this->dispatcher->getListenerPriority($eventName, $wrappedListener); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return $this->dispatcher->getListenerPriority($eventName, $listener); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * {@inheritdoc} | ||||
|      */ | ||||
|     public function hasListeners($eventName = null) | ||||
|     { | ||||
|         return $this->dispatcher->hasListeners($eventName); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * {@inheritdoc} | ||||
|      */ | ||||
|     public function dispatch($eventName, Event $event = null) | ||||
|     { | ||||
|         if (null === $this->callStack) { | ||||
|             $this->callStack = new \SplObjectStorage(); | ||||
|         } | ||||
|  | ||||
|         if (null === $event) { | ||||
|             $event = new Event(); | ||||
|         } | ||||
|  | ||||
|         if (null !== $this->logger && $event->isPropagationStopped()) { | ||||
|             $this->logger->debug(sprintf('The "%s" event is already stopped. No listeners have been called.', $eventName)); | ||||
|         } | ||||
|  | ||||
|         $this->preProcess($eventName); | ||||
|         try { | ||||
|             $this->preDispatch($eventName, $event); | ||||
|             try { | ||||
|                 $e = $this->stopwatch->start($eventName, 'section'); | ||||
|                 try { | ||||
|                     $this->dispatcher->dispatch($eventName, $event); | ||||
|                 } finally { | ||||
|                     if ($e->isStarted()) { | ||||
|                         $e->stop(); | ||||
|                     } | ||||
|                 } | ||||
|             } finally { | ||||
|                 $this->postDispatch($eventName, $event); | ||||
|             } | ||||
|         } finally { | ||||
|             $this->postProcess($eventName); | ||||
|         } | ||||
|  | ||||
|         return $event; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * {@inheritdoc} | ||||
|      */ | ||||
|     public function getCalledListeners() | ||||
|     { | ||||
|         if (null === $this->callStack) { | ||||
|             return []; | ||||
|         } | ||||
|  | ||||
|         $called = []; | ||||
|         foreach ($this->callStack as $listener) { | ||||
|             list($eventName) = $this->callStack->getInfo(); | ||||
|  | ||||
|             $called[] = $listener->getInfo($eventName); | ||||
|         } | ||||
|  | ||||
|         return $called; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * {@inheritdoc} | ||||
|      */ | ||||
|     public function getNotCalledListeners() | ||||
|     { | ||||
|         try { | ||||
|             $allListeners = $this->getListeners(); | ||||
|         } catch (\Exception $e) { | ||||
|             if (null !== $this->logger) { | ||||
|                 $this->logger->info('An exception was thrown while getting the uncalled listeners.', ['exception' => $e]); | ||||
|             } | ||||
|  | ||||
|             // unable to retrieve the uncalled listeners | ||||
|             return []; | ||||
|         } | ||||
|  | ||||
|         $calledListeners = []; | ||||
|  | ||||
|         if (null !== $this->callStack) { | ||||
|             foreach ($this->callStack as $calledListener) { | ||||
|                 $calledListeners[] = $calledListener->getWrappedListener(); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         $notCalled = []; | ||||
|         foreach ($allListeners as $eventName => $listeners) { | ||||
|             foreach ($listeners as $listener) { | ||||
|                 if (!\in_array($listener, $calledListeners, true)) { | ||||
|                     if (!$listener instanceof WrappedListener) { | ||||
|                         $listener = new WrappedListener($listener, null, $this->stopwatch, $this); | ||||
|                     } | ||||
|                     $notCalled[] = $listener->getInfo($eventName); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         uasort($notCalled, [$this, 'sortNotCalledListeners']); | ||||
|  | ||||
|         return $notCalled; | ||||
|     } | ||||
|  | ||||
|     public function getOrphanedEvents(): array | ||||
|     { | ||||
|         return $this->orphanedEvents; | ||||
|     } | ||||
|  | ||||
|     public function reset() | ||||
|     { | ||||
|         $this->callStack = null; | ||||
|         $this->orphanedEvents = []; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Proxies all method calls to the original event dispatcher. | ||||
|      * | ||||
|      * @param string $method    The method name | ||||
|      * @param array  $arguments The method arguments | ||||
|      * | ||||
|      * @return mixed | ||||
|      */ | ||||
|     public function __call($method, $arguments) | ||||
|     { | ||||
|         return $this->dispatcher->{$method}(...$arguments); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Called before dispatching the event. | ||||
|      * | ||||
|      * @param string $eventName The event name | ||||
|      * @param Event  $event     The event | ||||
|      */ | ||||
|     protected function preDispatch($eventName, Event $event) | ||||
|     { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Called after dispatching the event. | ||||
|      * | ||||
|      * @param string $eventName The event name | ||||
|      * @param Event  $event     The event | ||||
|      */ | ||||
|     protected function postDispatch($eventName, Event $event) | ||||
|     { | ||||
|     } | ||||
|  | ||||
|     private function preProcess($eventName) | ||||
|     { | ||||
|         if (!$this->dispatcher->hasListeners($eventName)) { | ||||
|             $this->orphanedEvents[] = $eventName; | ||||
|  | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         foreach ($this->dispatcher->getListeners($eventName) as $listener) { | ||||
|             $priority = $this->getListenerPriority($eventName, $listener); | ||||
|             $wrappedListener = new WrappedListener($listener instanceof WrappedListener ? $listener->getWrappedListener() : $listener, null, $this->stopwatch, $this); | ||||
|             $this->wrappedListeners[$eventName][] = $wrappedListener; | ||||
|             $this->dispatcher->removeListener($eventName, $listener); | ||||
|             $this->dispatcher->addListener($eventName, $wrappedListener, $priority); | ||||
|             $this->callStack->attach($wrappedListener, [$eventName]); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private function postProcess($eventName) | ||||
|     { | ||||
|         unset($this->wrappedListeners[$eventName]); | ||||
|         $skipped = false; | ||||
|         foreach ($this->dispatcher->getListeners($eventName) as $listener) { | ||||
|             if (!$listener instanceof WrappedListener) { // #12845: a new listener was added during dispatch. | ||||
|                 continue; | ||||
|             } | ||||
|             // Unwrap listener | ||||
|             $priority = $this->getListenerPriority($eventName, $listener); | ||||
|             $this->dispatcher->removeListener($eventName, $listener); | ||||
|             $this->dispatcher->addListener($eventName, $listener->getWrappedListener(), $priority); | ||||
|  | ||||
|             if (null !== $this->logger) { | ||||
|                 $context = ['event' => $eventName, 'listener' => $listener->getPretty()]; | ||||
|             } | ||||
|  | ||||
|             if ($listener->wasCalled()) { | ||||
|                 if (null !== $this->logger) { | ||||
|                     $this->logger->debug('Notified event "{event}" to listener "{listener}".', $context); | ||||
|                 } | ||||
|             } else { | ||||
|                 $this->callStack->detach($listener); | ||||
|             } | ||||
|  | ||||
|             if (null !== $this->logger && $skipped) { | ||||
|                 $this->logger->debug('Listener "{listener}" was not called for event "{event}".', $context); | ||||
|             } | ||||
|  | ||||
|             if ($listener->stoppedPropagation()) { | ||||
|                 if (null !== $this->logger) { | ||||
|                     $this->logger->debug('Listener "{listener}" stopped propagation of the event "{event}".', $context); | ||||
|                 } | ||||
|  | ||||
|                 $skipped = true; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private function sortNotCalledListeners(array $a, array $b) | ||||
|     { | ||||
|         if (0 !== $cmp = strcmp($a['event'], $b['event'])) { | ||||
|             return $cmp; | ||||
|         } | ||||
|  | ||||
|         if (\is_int($a['priority']) && !\is_int($b['priority'])) { | ||||
|             return 1; | ||||
|         } | ||||
|  | ||||
|         if (!\is_int($a['priority']) && \is_int($b['priority'])) { | ||||
|             return -1; | ||||
|         } | ||||
|  | ||||
|         if ($a['priority'] === $b['priority']) { | ||||
|             return 0; | ||||
|         } | ||||
|  | ||||
|         if ($a['priority'] > $b['priority']) { | ||||
|             return -1; | ||||
|         } | ||||
|  | ||||
|         return 1; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										37
									
								
								vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcherInterface.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcherInterface.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,37 @@ | ||||
| <?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\Contracts\Service\ResetInterface; | ||||
|  | ||||
| /** | ||||
|  * @deprecated since Symfony 4.1 | ||||
|  * | ||||
|  * @author Fabien Potencier <fabien@symfony.com> | ||||
|  */ | ||||
| interface TraceableEventDispatcherInterface extends EventDispatcherInterface, ResetInterface | ||||
| { | ||||
|     /** | ||||
|      * Gets the called listeners. | ||||
|      * | ||||
|      * @return array An array of called listeners | ||||
|      */ | ||||
|     public function getCalledListeners(); | ||||
|  | ||||
|     /** | ||||
|      * Gets the not called listeners. | ||||
|      * | ||||
|      * @return array An array of not called listeners | ||||
|      */ | ||||
|     public function getNotCalledListeners(); | ||||
| } | ||||
							
								
								
									
										125
									
								
								vendor/symfony/event-dispatcher/Debug/WrappedListener.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										125
									
								
								vendor/symfony/event-dispatcher/Debug/WrappedListener.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,125 @@ | ||||
| <?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\Event; | ||||
| use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||||
| use Symfony\Component\Stopwatch\Stopwatch; | ||||
| use Symfony\Component\VarDumper\Caster\ClassStub; | ||||
|  | ||||
| /** | ||||
|  * @author Fabien Potencier <fabien@symfony.com> | ||||
|  */ | ||||
| class WrappedListener | ||||
| { | ||||
|     private $listener; | ||||
|     private $name; | ||||
|     private $called; | ||||
|     private $stoppedPropagation; | ||||
|     private $stopwatch; | ||||
|     private $dispatcher; | ||||
|     private $pretty; | ||||
|     private $stub; | ||||
|     private $priority; | ||||
|     private static $hasClassStub; | ||||
|  | ||||
|     public function __construct($listener, $name, Stopwatch $stopwatch, EventDispatcherInterface $dispatcher = null) | ||||
|     { | ||||
|         $this->listener = $listener; | ||||
|         $this->stopwatch = $stopwatch; | ||||
|         $this->dispatcher = $dispatcher; | ||||
|         $this->called = false; | ||||
|         $this->stoppedPropagation = false; | ||||
|  | ||||
|         if (\is_array($listener)) { | ||||
|             $this->name = \is_object($listener[0]) ? \get_class($listener[0]) : $listener[0]; | ||||
|             $this->pretty = $this->name.'::'.$listener[1]; | ||||
|         } elseif ($listener instanceof \Closure) { | ||||
|             $r = new \ReflectionFunction($listener); | ||||
|             if (false !== strpos($r->name, '{closure}')) { | ||||
|                 $this->pretty = $this->name = 'closure'; | ||||
|             } elseif ($class = $r->getClosureScopeClass()) { | ||||
|                 $this->name = $class->name; | ||||
|                 $this->pretty = $this->name.'::'.$r->name; | ||||
|             } else { | ||||
|                 $this->pretty = $this->name = $r->name; | ||||
|             } | ||||
|         } elseif (\is_string($listener)) { | ||||
|             $this->pretty = $this->name = $listener; | ||||
|         } else { | ||||
|             $this->name = \get_class($listener); | ||||
|             $this->pretty = $this->name.'::__invoke'; | ||||
|         } | ||||
|  | ||||
|         if (null !== $name) { | ||||
|             $this->name = $name; | ||||
|         } | ||||
|  | ||||
|         if (null === self::$hasClassStub) { | ||||
|             self::$hasClassStub = class_exists(ClassStub::class); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public function getWrappedListener() | ||||
|     { | ||||
|         return $this->listener; | ||||
|     } | ||||
|  | ||||
|     public function wasCalled() | ||||
|     { | ||||
|         return $this->called; | ||||
|     } | ||||
|  | ||||
|     public function stoppedPropagation() | ||||
|     { | ||||
|         return $this->stoppedPropagation; | ||||
|     } | ||||
|  | ||||
|     public function getPretty() | ||||
|     { | ||||
|         return $this->pretty; | ||||
|     } | ||||
|  | ||||
|     public function getInfo($eventName) | ||||
|     { | ||||
|         if (null === $this->stub) { | ||||
|             $this->stub = self::$hasClassStub ? new ClassStub($this->pretty.'()', $this->listener) : $this->pretty.'()'; | ||||
|         } | ||||
|  | ||||
|         return [ | ||||
|             'event' => $eventName, | ||||
|             'priority' => null !== $this->priority ? $this->priority : (null !== $this->dispatcher ? $this->dispatcher->getListenerPriority($eventName, $this->listener) : null), | ||||
|             'pretty' => $this->pretty, | ||||
|             'stub' => $this->stub, | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
|     public function __invoke(Event $event, $eventName, EventDispatcherInterface $dispatcher) | ||||
|     { | ||||
|         $dispatcher = $this->dispatcher ?: $dispatcher; | ||||
|  | ||||
|         $this->called = true; | ||||
|         $this->priority = $dispatcher->getListenerPriority($eventName, $this->listener); | ||||
|  | ||||
|         $e = $this->stopwatch->start($this->name, 'event_listener'); | ||||
|  | ||||
|         ($this->listener)($event, $eventName, $dispatcher); | ||||
|  | ||||
|         if ($e->isStarted()) { | ||||
|             $e->stop(); | ||||
|         } | ||||
|  | ||||
|         if ($event->isPropagationStopped()) { | ||||
|             $this->stoppedPropagation = true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user