You are here

class ServicesDataCollector in Devel 4.x

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

Class ServicesDataCollector.

Hierarchy

Expanded class hierarchy of ServicesDataCollector

1 string reference to 'ServicesDataCollector'
webprofiler.services.yml in webprofiler/webprofiler.services.yml
webprofiler/webprofiler.services.yml
1 service uses ServicesDataCollector
webprofiler.services in webprofiler/webprofiler.services.yml
Drupal\webprofiler\DataCollector\ServicesDataCollector

File

webprofiler/src/DataCollector/ServicesDataCollector.php, line 16

Namespace

Drupal\webprofiler\DataCollector
View source
class ServicesDataCollector extends DataCollector implements DrupalDataCollectorInterface {
  use StringTranslationTrait, DrupalDataCollectorTrait;

  /**
   * @var \Symfony\Component\DependencyInjection\ContainerInterface
   *   $container
   */
  private $container;

  /**
   * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
   */
  public function __construct(ContainerInterface $container) {
    $this->container = $container;
  }

  /**
   * {@inheritdoc}
   */
  public function collect(Request $request, Response $response, \Exception $exception = NULL) {
    if ($this
      ->getServicesCount()) {
      $tracedData = [];
      if ($this->container instanceof TraceableContainer) {
        $tracedData = $this->container
          ->getTracedData();
      }
      foreach (array_keys($this
        ->getServices()) as $id) {
        $this->data['services'][$id]['initialized'] = $this->container
          ->initialized($id) ? TRUE : FALSE;
        $this->data['services'][$id]['time'] = isset($tracedData[$id]) ? $tracedData[$id] : NULL;
      }
    }
  }

  /**
   * @param $services
   */
  public function setServices($services) {
    $this->data['services'] = $services;
  }

  /**
   * @return array
   */
  public function getServices() {
    return $this->data['services'];
  }

  /**
   * @return int
   */
  public function getServicesCount() {
    return count($this
      ->getServices());
  }

  /**
   * @return array
   */
  public function getInitializedServices() {
    return array_filter($this
      ->getServices(), function ($item) {
      return $item['initialized'];
    });
  }

  /**
   * @return int
   */
  public function getInitializedServicesCount() {
    return count($this
      ->getInitializedServices());
  }

  /**
   * @return array
   */
  public function getInitializedServicesWithoutWebprofiler() {
    return array_filter($this
      ->getInitializedServices(), function ($item) {
      return strpos($item['value']['id'], 'webprofiler') !== 0;
    });
  }

  /**
   * @return int
   */
  public function getInitializedServicesWithoutWebprofilerCount() {
    return count($this
      ->getInitializedServicesWithoutWebprofiler());
  }

  /**
   * {@inheritdoc}
   */
  public function getName() {
    return 'services';
  }

  /**
   * {@inheritdoc}
   */
  public function getTitle() {
    return $this
      ->t('Services');
  }

  /**
   * {@inheritdoc}
   */
  public function getPanelSummary() {
    return $this
      ->t('Initialized: @count', [
      '@count' => $this
        ->getInitializedServicesCount(),
    ]);
  }

  /**
   * {@inheritdoc}
   */
  public function getIcon() {
    return 'iVBORw0KGgoAAAANSUhEUgAAABUAAAAcCAYAAACOGPReAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQVJREFUeNrkVe0NgjAQBeMAdYO6AWxQNtANGEFHcALZANyADegGsIFsIBvgu6Q/LtWmxdTEjyYvd6Hw8t5de6TzPCex1yp5w/pz0rVrQymVIXSAACqt9TGG0p0hpHWIZb9lebWENOXn1FgWbL8GJHACNHs+ohyjlxSEZPEcKGYC6SbEvljgUHzEOR3IXiiB6YOTlLqdo1Y54tZHDLIauCHtETtn962P6EUVqhhi0gelIJEEk1MjMg9Py9xol/0SuBqFva/DULY3ZSqQF767v8TyZKv83tFXWVaEufsUG+DCr2nwQLGOlGQNizZPy3fMU16K5uV5+qQEpFTC+hCN9Pd/0XcBBgBxwVqjDkAznAAAAABJRU5ErkJggg==';
  }

  /**
   * @return array
   */
  public function getData() {
    $data = $this->data;
    $http_middleware = array_filter($data['services'], function ($service) {
      return isset($service['value']['tags']['http_middleware']);
    });
    foreach ($http_middleware as &$service) {
      $service['value']['handle_method'] = $this
        ->getMethodData($service['value']['class'], 'handle');
    }
    uasort($http_middleware, function ($a, $b) {
      $va = $a['value']['tags']['http_middleware'][0]['priority'];
      $vb = $b['value']['tags']['http_middleware'][0]['priority'];
      if ($va == $vb) {
        return 0;
      }
      return $va > $vb ? -1 : 1;
    });
    $data['http_middleware'] = $http_middleware;
    return $data;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalDataCollectorInterface::getDrupalSettings public function 1
DrupalDataCollectorInterface::getLibraries public function Returns the libraries needed in detail panel. 2
DrupalDataCollectorInterface::hasPanel public function Returns true if this datacollector has a detail panel. 2
ServicesDataCollector::$container private property $container
ServicesDataCollector::collect public function
ServicesDataCollector::getData public function Overrides DrupalDataCollectorInterface::getData
ServicesDataCollector::getIcon public function Returns the collector icon in base64 format. Overrides DrupalDataCollectorInterface::getIcon
ServicesDataCollector::getInitializedServices public function
ServicesDataCollector::getInitializedServicesCount public function
ServicesDataCollector::getInitializedServicesWithoutWebprofiler public function
ServicesDataCollector::getInitializedServicesWithoutWebprofilerCount public function
ServicesDataCollector::getName public function Returns the name of the collector. Overrides DrupalDataCollectorInterface::getName
ServicesDataCollector::getPanelSummary public function Returns the string used in vertical tab summary. Overrides DrupalDataCollectorInterface::getPanelSummary
ServicesDataCollector::getServices public function
ServicesDataCollector::getServicesCount public function
ServicesDataCollector::getTitle public function Returns the datacollector title. Overrides DrupalDataCollectorInterface::getTitle
ServicesDataCollector::setServices public function
ServicesDataCollector::__construct public function
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.