Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. TraceableEventDispatcher.php

class TraceableEventDispatcher

Same name in this branch
  1. 11.1.x vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php \Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher

Collects some data about event listeners.

This event dispatcher delegates the dispatching to another one.

@author Fabien Potencier <fabien@symfony.com>

Hierarchy

  • class \Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher implements \Symfony\Component\EventDispatcher\EventDispatcherInterface, \Symfony\Contracts\Service\ResetInterface
    • class \Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher extends \Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher

Expanded class hierarchy of TraceableEventDispatcher

File

vendor/symfony/http-kernel/Debug/TraceableEventDispatcher.php, line 24

Namespace

Symfony\Component\HttpKernel\Debug
View source
class TraceableEventDispatcher extends BaseTraceableEventDispatcher {
    protected function beforeDispatch(string $eventName, object $event) : void {
        switch ($eventName) {
            case KernelEvents::REQUEST:
                $event->getRequest()->attributes
                    ->set('_stopwatch_token', bin2hex(random_bytes(3)));
                $this->stopwatch
                    ->openSection();
                break;
            case KernelEvents::VIEW:
            case KernelEvents::RESPONSE:
                // stop only if a controller has been executed
                if ($this->stopwatch
                    ->isStarted('controller')) {
                    $this->stopwatch
                        ->stop('controller');
                }
                break;
            case KernelEvents::TERMINATE:
                $sectionId = $event->getRequest()->attributes
                    ->get('_stopwatch_token');
                if (null === $sectionId) {
                    break;
                }
                // There is a very special case when using built-in AppCache class as kernel wrapper, in the case
                // of an ESI request leading to a `stale` response [B]  inside a `fresh` cached response [A].
                // In this case, `$token` contains the [B] debug token, but the  open `stopwatch` section ID
                // is equal to the [A] debug token. Trying to reopen section with the [B] token throws an exception
                // which must be caught.
                try {
                    $this->stopwatch
                        ->openSection($sectionId);
                } catch (\LogicException) {
                }
                break;
        }
    }
    protected function afterDispatch(string $eventName, object $event) : void {
        switch ($eventName) {
            case KernelEvents::CONTROLLER_ARGUMENTS:
                $this->stopwatch
                    ->start('controller', 'section');
                break;
            case KernelEvents::RESPONSE:
                $sectionId = $event->getRequest()->attributes
                    ->get('_stopwatch_token');
                if (null === $sectionId) {
                    break;
                }
                $this->stopwatch
                    ->stopSection($sectionId);
                break;
            case KernelEvents::TERMINATE:
                // In the special case described in the `preDispatch` method above, the `$token` section
                // does not exist, then closing it throws an exception which must be caught.
                $sectionId = $event->getRequest()->attributes
                    ->get('_stopwatch_token');
                if (null === $sectionId) {
                    break;
                }
                try {
                    $this->stopwatch
                        ->stopSection($sectionId);
                } catch (\LogicException) {
                }
                break;
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
TraceableEventDispatcher::$callStack private property
TraceableEventDispatcher::$currentRequestHash private property
TraceableEventDispatcher::$orphanedEvents private property
TraceableEventDispatcher::$wrappedListeners private property
TraceableEventDispatcher::addListener public function Adds an event listener that listens on the specified events. Overrides EventDispatcherInterface::addListener
TraceableEventDispatcher::addSubscriber public function Adds an event subscriber. Overrides EventDispatcherInterface::addSubscriber
TraceableEventDispatcher::afterDispatch protected function Called after dispatching the event. Overrides TraceableEventDispatcher::afterDispatch
TraceableEventDispatcher::beforeDispatch protected function Called before dispatching the event. Overrides TraceableEventDispatcher::beforeDispatch
TraceableEventDispatcher::dispatch public function Dispatches an event to all registered listeners. Overrides EventDispatcherInterface::dispatch
TraceableEventDispatcher::getCalledListeners public function
TraceableEventDispatcher::getListenerPriority public function Gets the listener priority for a specific event. Overrides EventDispatcherInterface::getListenerPriority
TraceableEventDispatcher::getListeners public function Gets the listeners of a specific event or all listeners sorted by descending priority. Overrides EventDispatcherInterface::getListeners
TraceableEventDispatcher::getListenersWithoutPriority private function
TraceableEventDispatcher::getListenersWithPriority private function
TraceableEventDispatcher::getNotCalledListeners public function
TraceableEventDispatcher::getOrphanedEvents public function
TraceableEventDispatcher::hasListeners public function Checks whether an event has any registered listeners. Overrides EventDispatcherInterface::hasListeners
TraceableEventDispatcher::postProcess private function
TraceableEventDispatcher::preProcess private function
TraceableEventDispatcher::removeListener public function Removes an event listener from the specified events. Overrides EventDispatcherInterface::removeListener
TraceableEventDispatcher::removeSubscriber public function Overrides EventDispatcherInterface::removeSubscriber
TraceableEventDispatcher::reset public function Overrides ResetInterface::reset
TraceableEventDispatcher::sortNotCalledListeners private function
TraceableEventDispatcher::__call public function Proxies all method calls to the original event dispatcher.
TraceableEventDispatcher::__construct public function

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal