3 namespace Drupal\webprofiler\DataCollector;
5 use Drupal\Core\StringTranslation\StringTranslationTrait;
6 use Drupal\webprofiler\DependencyInjection\TraceableContainer;
7 use Drupal\webprofiler\DrupalDataCollectorInterface;
8 use Symfony\Component\DependencyInjection\IntrospectableContainerInterface;
9 use Symfony\Component\HttpFoundation\Request;
10 use Symfony\Component\HttpFoundation\Response;
11 use Symfony\Component\HttpKernel\DataCollector\DataCollector;
14 * Class ServicesDataCollector
16 class ServicesDataCollector extends DataCollector implements DrupalDataCollectorInterface {
18 use StringTranslationTrait, DrupalDataCollectorTrait;
21 * @var \Symfony\Component\DependencyInjection\IntrospectableContainerInterface
27 * @param IntrospectableContainerInterface $container
29 public function __construct(IntrospectableContainerInterface $container) {
30 $this->container = $container;
36 public function collect(Request $request, Response $response, \Exception $exception = NULL) {
37 if ($this->getServicesCount()) {
40 if ($this->container instanceof TraceableContainer) {
41 $tracedData = $this->container->getTracedData();
44 foreach (array_keys($this->getServices()) as $id) {
45 $this->data['services'][$id]['initialized'] = ($this->container->initialized($id)) ? TRUE : FALSE;
46 $this->data['services'][$id]['time'] = isset($tracedData[$id]) ? $tracedData[$id] : NULL;
54 public function setServices($services) {
55 $this->data['services'] = $services;
61 public function getServices() {
62 return $this->data['services'];
68 public function getServicesCount() {
69 return count($this->getServices());
75 public function getInitializedServices() {
76 return array_filter($this->getServices(), function($item) {
77 return $item['initialized'];
84 public function getInitializedServicesCount() {
85 return count($this->getInitializedServices());
91 public function getInitializedServicesWithoutWebprofiler() {
92 return array_filter($this->getInitializedServices(), function($item) {
93 return strpos($item['value']['id'], 'webprofiler') !== 0;
100 public function getInitializedServicesWithoutWebprofilerCount() {
101 return count($this->getInitializedServicesWithoutWebprofiler());
107 public function getName() {
114 public function getTitle() {
115 return $this->t('Services');
121 public function getPanelSummary() {
122 return $this->t('Initialized: @count', [
123 '@count' => $this->getInitializedServicesCount(),
130 public function getIcon() {
131 return 'iVBORw0KGgoAAAANSUhEUgAAABUAAAAcCAYAAACOGPReAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQVJREFUeNrkVe0NgjAQBeMAdYO6AWxQNtANGEFHcALZANyADegGsIFsIBvgu6Q/LtWmxdTEjyYvd6Hw8t5de6TzPCex1yp5w/pz0rVrQymVIXSAACqt9TGG0p0hpHWIZb9lebWENOXn1FgWbL8GJHACNHs+ohyjlxSEZPEcKGYC6SbEvljgUHzEOR3IXiiB6YOTlLqdo1Y54tZHDLIauCHtETtn962P6EUVqhhi0gelIJEEk1MjMg9Py9xol/0SuBqFva/DULY3ZSqQF767v8TyZKv83tFXWVaEufsUG+DCr2nwQLGOlGQNizZPy3fMU16K5uV5+qQEpFTC+hCN9Pd/0XcBBgBxwVqjDkAznAAAAABJRU5ErkJggg==';
137 public function getData() {
140 $http_middleware = array_filter($data['services'], function($service) {
141 return isset($service['value']['tags']['http_middleware']);
144 foreach ($http_middleware as &$service) {
145 $service['value']['handle_method'] = $this->getMethodData($service['value']['class'], 'handle');
148 uasort($http_middleware, function ($a, $b) {
149 $va = $a['value']['tags']['http_middleware'][0]['priority'];
150 $vb = $b['value']['tags']['http_middleware'][0]['priority'];
155 return ($va > $vb) ? -1 : 1;
158 $data['http_middleware'] = $http_middleware;