EventsDataCollector.php in Devel 8
File
webprofiler/src/DataCollector/EventsDataCollector.php
View source
<?php
namespace Drupal\webprofiler\DataCollector;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\webprofiler\DrupalDataCollectorInterface;
use Drupal\webprofiler\EventDispatcher\EventDispatcherTraceableInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface;
class EventsDataCollector extends DataCollector implements DrupalDataCollectorInterface, LateDataCollectorInterface {
use StringTranslationTrait, DrupalDataCollectorTrait;
private $eventDispatcher;
public function __construct(EventDispatcherInterface $event_dispatcher) {
$this->eventDispatcher = $event_dispatcher;
}
public function collect(Request $request, Response $response, \Exception $exception = NULL) {
$this->data = [
'called_listeners' => [],
'called_listeners_count' => 0,
'not_called_listeners' => [],
'not_called_listeners_count' => 0,
];
}
public function lateCollect() {
if ($this->eventDispatcher instanceof EventDispatcherTraceableInterface) {
$countCalled = 0;
$calledListeners = $this->eventDispatcher
->getCalledListeners();
foreach ($calledListeners as &$events) {
foreach ($events as &$priority) {
foreach ($priority as &$listener) {
$countCalled++;
$listener['clazz'] = $this
->getMethodData($listener['class'], $listener['method']);
}
}
}
$countNotCalled = 0;
$notCalledListeners = $this->eventDispatcher
->getNotCalledListeners();
foreach ($notCalledListeners as $events) {
foreach ($events as $priority) {
foreach ($priority as $listener) {
$countNotCalled++;
}
}
}
$this->data = [
'called_listeners' => $calledListeners,
'called_listeners_count' => $countCalled,
'not_called_listeners' => $notCalledListeners,
'not_called_listeners_count' => $countNotCalled,
];
}
}
public function getCalledListeners() {
return $this->data['called_listeners'];
}
public function getNotCalledListeners() {
return $this->data['not_called_listeners'];
}
public function getCalledListenersCount() {
return $this->data['called_listeners_count'];
}
public function getNotCalledListenersCount() {
return $this->data['not_called_listeners_count'];
}
public function getName() {
return 'events';
}
public function getData() {
return $this->data;
}
public function getTitle() {
return $this
->t('Events');
}
public function getPanelSummary() {
return $this
->t('Called listeners: @listeners', [
'@listeners' => $this
->getCalledListenersCount(),
]);
}
public function getIcon() {
return 'iVBORw0KGgoAAAANSUhEUgAAABUAAAAcCAYAAACOGPReAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAABFJJREFUeNrkVVlIY2cY/RMTE81NMkkajUs1OBqkiVsjjAtStGrtSGyFjOjAQNVCKRb66ot9KrjgQx+FUgTBKkURbIfighWl4r6h44pajcZEo3ESTeKS9PzB2AyNZaD1qRcOem+S83/f+c53Lsvj8ZD/+mKTB7gehJTj+2d9fZ1MTk6S0NBQSW9vb97e3t7jmpqaXzIzM185HA7vd4KDg8nGxoaysbGxVCwWm/V6/aDL5TKlpKSQpKSkv5NyuVxyc3Mj7e7u/jw2NjYxJyfnMDIykmGz2UQgEBAWi0XcbjeRSqWhZWVl4v39fXVXV5cqNzf3exxmCNj+9fU1MzQ09JVWq32sUqmMu7u7QhwiDwoKIoeHh2R7e5twOByCwcrQhUShUJjz8vJkw8PDX5+fn8sDkvb3938YHR39rlAoNBoMBgGqtWxubnJRKbu9vZ20trZSQoJnvKioKMvZ2Rn/6urKmpqayvT19ekCks7NzaUnJyeboK0kPj7+cGZmJprH4zGnp6duEBFUTg4ODqjmIfPz87GQxoRnori4ODOKUPuTsnw+RRvPGIYJMZvNDNplYmJiLvPz839oamoSj4yMfAJNuRqN5mV9ff0fOPDF1NSUAt85lclkDkjnys7O/vGOlZLeQgjIgUggnmqHqmMqKip+z8jI8MAFnpKSkpXZ2dn38JkIUAFRQNjt/R2Xv09twBFwAGwClunp6efLy8tZdFgUW1tbiaOjo1/is9fUhcA+YL69fzvzSyQSEQZHfBJBT4J2Bf9qo9Rq9bxcLndeXl4STJrA8B4Mc/atN4pesAk5OTkh1PB0exYXF/kWi4UTFhZG+Hw+wZQJ5BDR7fEPIroYASu9uLggJpOJ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