You are here

class TraceableContainer in Devel 4.x

Same name and namespace in other branches
  1. 8.3 webprofiler/src/DependencyInjection/TraceableContainer.php \Drupal\webprofiler\DependencyInjection\TraceableContainer
  2. 8 webprofiler/src/DependencyInjection/TraceableContainer.php \Drupal\webprofiler\DependencyInjection\TraceableContainer
  3. 8.2 webprofiler/src/DependencyInjection/TraceableContainer.php \Drupal\webprofiler\DependencyInjection\TraceableContainer

Extends the Drupal container class to trace service instantiations.

Hierarchy

  • class \Drupal\Component\DependencyInjection\Container implements \Symfony\Component\DependencyInjection\ContainerInterface, \Symfony\Contracts\Service\ResetInterface

Expanded class hierarchy of TraceableContainer

1 file declares its use of TraceableContainer
ServicesDataCollector.php in webprofiler/src/DataCollector/ServicesDataCollector.php

File

webprofiler/src/DependencyInjection/TraceableContainer.php, line 11

Namespace

Drupal\webprofiler\DependencyInjection
View source
class TraceableContainer extends Container {

  /**
   * @var array
   */
  protected $tracedData;

  /**
   * @var \Symfony\Component\Stopwatch\Stopwatch
   */
  private $stopwatch = NULL;

  /**
   * @var bool
   */
  private $hasStopwatch = FALSE;

  /**
   * @param string $id
   * @param int $invalidBehavior
   *
   * @return object
   */
  public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE) {
    if (!$this->stopwatch && $this
      ->has('stopwatch')) {
      $this->stopwatch = parent::get('stopwatch');
      $this->stopwatch
        ->openSection();
      $this->hasStopwatch = TRUE;
    }
    if ('stopwatch' === $id) {
      return $this->stopwatch;
    }
    Timer::start($id);
    if ($this->hasStopwatch) {
      $e = $this->stopwatch
        ->start($id, 'service');
    }
    $service = parent::get($id, $invalidBehavior);
    $this->tracedData[$id] = Timer::stop($id);
    if ($this->hasStopwatch && $e
      ->isStarted()) {
      $e
        ->stop();
    }
    return $service;
  }

  /**
   * @return array
   */
  public function getTracedData() {
    return $this->tracedData;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Container::$aliases protected property The aliases of the container.
Container::$frozen protected property Whether the container parameters can still be changed.
Container::$loading protected property The currently loading services.
Container::$parameters protected property The parameters of the container.
Container::$privateServices protected property The instantiated private services.
Container::$serviceDefinitions protected property The service definitions of the container.
Container::$services protected property The instantiated services.
Container::createService protected function Creates a service from a service definition. 1
Container::getAlternatives protected function Provides alternatives for a given array and key.
Container::getParameter public function
Container::getParameterAlternatives protected function Provides alternatives in case a parameter was not found.
Container::getServiceAlternatives protected function Provides alternatives in case a service was not found.
Container::getServiceIds public function Gets all defined service IDs.
Container::has public function
Container::hasParameter public function
Container::initialized public function
Container::reset public function Resets shared services from the container.
Container::resolveServicesAndParameters protected function Resolves arguments that represent services or variables to the real values. 1
Container::set public function Overrides Container::set
Container::setParameter public function
Container::__clone private function Ensure that cloning doesn't work.
Container::__construct public function Constructs a new Container instance. 1
Container::__sleep public function
TraceableContainer::$hasStopwatch private property
TraceableContainer::$stopwatch private property
TraceableContainer::$tracedData protected property
TraceableContainer::get public function Overrides Container::get
TraceableContainer::getTracedData public function