You are here

public function XHProfEventSubscriber::onKernelResponse in XHProf 8

Renders link to the finished run.

Parameters

\Symfony\Component\HttpKernel\Event\FilterResponseEvent $event: The event.

File

src/EventSubscriber/XHProfEventSubscriber.php, line 92

Class

XHProfEventSubscriber
Provides handling of start/stop for profiler.

Namespace

Drupal\xhprof\EventSubscriber

Code

public function onKernelResponse(FilterResponseEvent $event) {
  if ($this->profiler
    ->isEnabled()) {
    $this->xhprofRunId = $this->profiler
      ->createRunId();

    // Don't print the link to xhprof run page if
    // Webprofiler module is enabled, a widget will
    // be rendered into Webprofiler toolbar.
    if (!$this->moduleHandler
      ->moduleExists('webprofiler')) {
      $response = $event
        ->getResponse();

      // Try not to break non html pages.
      $formats = [
        'xml',
        'javascript',
        'json',
        'plain',
        'image',
        'application',
        'csv',
        'x-comma-separated-values',
      ];
      foreach ($formats as $format) {
        if ($response->headers
          ->get($format)) {
          return;
        }
      }
      if ($this->currentUser
        ->hasPermission('access xhprof data')) {
        $this
          ->injectLink($response, $this->xhprofRunId);
      }
    }
  }
}