You are here

class RequestDataCollector in Devel 8

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

Integrate _content into the RequestDataCollector

Hierarchy

Expanded class hierarchy of RequestDataCollector

1 file declares its use of RequestDataCollector
AccessManagerWrapper.php in webprofiler/src/Access/AccessManagerWrapper.php
1 string reference to 'RequestDataCollector'
webprofiler.services.yml in webprofiler/webprofiler.services.yml
webprofiler/webprofiler.services.yml
1 service uses RequestDataCollector
webprofiler.request in webprofiler/webprofiler.services.yml
Drupal\webprofiler\DataCollector\RequestDataCollector

File

webprofiler/src/DataCollector/RequestDataCollector.php, line 15

Namespace

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

  /**
   * @var \Drupal\Core\Controller\ControllerResolverInterface
   */
  private $controllerResolver;

  /**
   * @var array
   */
  private $accessCheck;

  /**
   * @param \Drupal\Core\Controller\ControllerResolverInterface $controllerResolver
   */
  public function __construct(ControllerResolverInterface $controllerResolver) {
    parent::__construct();
    $this->controllerResolver = $controllerResolver;
    $this->accessCheck = [];
  }

  /**
   * {@inheritdoc}
   */
  public function collect(Request $request, Response $response, \Exception $exception = NULL) {
    parent::collect($request, $response, $exception);
    $controller = $this->controllerResolver
      ->getController($request);
    $this->data['controller'] = $this
      ->getMethodData($controller[0], $controller[1]);
    $this->data['access_check'] = $this->accessCheck;
  }

  /**
   * @param $service_id
   * @param $callable
   * @param \Symfony\Component\HttpFoundation\Request $request
   *
   */
  public function addAccessCheck($service_id, $callable, Request $request) {
    $this->accessCheck[$request
      ->getPathInfo()][] = [
      'service_id' => $service_id,
      'callable' => $this
        ->getMethodData($callable[0], $callable[1]),
    ];
  }

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

  /**
   * {@inheritdoc}
   */
  public function getPanelSummary() {
    return $this->data['status_code'] . ' ' . $this->data['status_text'];
  }

  /**
   * {@inheritdoc}
   */
  public function getIcon() {
    return 'iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAQAAADYBBcfAAACvElEQVR42tVTbUhTYRTerDCnKVoUUr/KCZmypA9Koet0bXNLJ5XazDJ/WFaCUY0pExRZXxYiJgsxWWjkaL+yK+po1gjyR2QfmqWxtBmaBtqWGnabT++c11Fu4l/P4VzOPc95zoHznsNZodIbLDdRcKnc1Bu8DAK45ZsOnykQNMopsNooLxCknb0cDq5vml9FtHiIgpBR0R6iihYyFMTDt2Lg56ObPkI6TMGXSof1EV67IqCwisJSWliFAG/E0CfFIiebdNypcxi/1zgyFiIiZ3sJQr0RQx5frLa6k7SOKRo3oMFNR5t62h2rttKXEOKFqDCxtXNmmBokO2KKTlp3IdWuT2dYRNGKwEXEBCcL172G5FG0aIxC0kR9PBTVH1kkwQn+IqJnCE33EalVzT9GJQS1tAdD3CKicJYFrxqx7W2ejCEdZy1FiC5tZxHhLJKOZaRdQJAyV/YAvDliySALHxmxR4Hqe2iwvaOR/CEuZYJFSgYhVbZRkA8KGdEktrqnqra90NndCdkt77fjIHIhexOrfO6O3bbbOj/rqu5IptgyR3sU93QbOYhquZK4MCDp0Ina/PLsu5JvbCTRaapUdUmIV/RzoMdsk/0hWRNdAvKOmvqlN0drsJbJf1P4YsQ5lGrJeuosiOUgbOC8cto3LfOXTdVd7BqZsQKbse+0jUL6WPcesqs4MNSUTQAxGjwFiC8m3yzmqwHJBWYKBJ9WNqW/dHkpU/osch1Yj5RJfXPfSEe/2UPsN490NPfZG5CKyJmcV5ayHyzy7BMqsXfuHhGK/cjAIeSpR92gehR55D8TcQhDEKJwytBJ4fr4NULvrEM8NszfJPyxDoHYAQ1oPCWmIX4gifmDS/DV2DKeb25FHWr76yEG7/9L4YFPeiQQ4/8LkgJ8Et+NncTCsYqzXAEXa7CWdPZzGWdlyV+vST0JanfPvwAAAABJRU5ErkJggg==';
  }

  /**
   * @return array|string
   */
  public function getData() {

    // Drupal 8.5+ uses Symfony 3.4.x that changes the way the Request data are
    // collected. Data is altered with \Symfony\Component\HttpKernel\DataCollector\DataCollector::cloneVar.
    // The stored data (of type \Symfony\Component\VarDumper\Cloner\Data) is
    // suitable to be converted to a string by a Dumper (\Symfony\Component\VarDumper\Dumper\DataDumperInterface).
    // In our implementation however we need that data as an array, to be later
    // converted in a json response by a REST endpoint. We need to refactor the
    // whole way Web Profiler works to allow that. At the moment we just
    // retrieve the raw Data value and do some string manipulation to clean the
    // output a bit.
    $data = $this->data
      ->getValue(TRUE);
    unset($data['request_attributes']['_route_params']);
    unset($data['request_attributes']['_access_result']);
    $route_object = [];
    foreach ($data['request_attributes']['_route_object'] as $key => $result) {
      $key = str_replace("\0", '', $key);
      $key = str_replace('Symfony\\Component\\Routing\\Route', 'Symfony\\Component\\Routing\\Route::', $key);
      $route_object[$key] = $result;
    }
    $data['request_attributes']['_route_object'] = $route_object;
    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::getName public function Returns the name of the collector. 21
DrupalDataCollectorInterface::hasPanel public function Returns true if this datacollector has a detail panel. 2
RequestDataCollector::$accessCheck private property
RequestDataCollector::$controllerResolver private property
RequestDataCollector::addAccessCheck public function
RequestDataCollector::collect public function Collects data for the given Request and Response.
RequestDataCollector::getData public function Overrides DrupalDataCollectorInterface::getData
RequestDataCollector::getIcon public function Returns the collector icon in base64 format. Overrides DrupalDataCollectorInterface::getIcon
RequestDataCollector::getPanelSummary public function Returns the string used in vertical tab summary. Overrides DrupalDataCollectorInterface::getPanelSummary
RequestDataCollector::getTitle public function Returns the datacollector title. Overrides DrupalDataCollectorInterface::getTitle
RequestDataCollector::__construct public function
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
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.