class WebprofilerEventSubscriber in Devel 4.x
Same name and namespace in other branches
- 8.3 webprofiler/src/EventSubscriber/WebprofilerEventSubscriber.php \Drupal\webprofiler\EventSubscriber\WebprofilerEventSubscriber
- 8 webprofiler/src/EventSubscriber/WebprofilerEventSubscriber.php \Drupal\webprofiler\EventSubscriber\WebprofilerEventSubscriber
- 8.2 webprofiler/src/EventSubscriber/WebprofilerEventSubscriber.php \Drupal\webprofiler\EventSubscriber\WebprofilerEventSubscriber
Class WebprofilerEventSubscriber.
Hierarchy
- class \Drupal\webprofiler\EventSubscriber\WebprofilerEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of WebprofilerEventSubscriber
1 string reference to 'WebprofilerEventSubscriber'
- webprofiler.services.yml in webprofiler/
webprofiler.services.yml - webprofiler/webprofiler.services.yml
1 service uses WebprofilerEventSubscriber
File
- webprofiler/
src/ EventSubscriber/ WebprofilerEventSubscriber.php, line 16
Namespace
Drupal\webprofiler\EventSubscriberView source
class WebprofilerEventSubscriber implements EventSubscriberInterface {
/**
* @var \Drupal\Core\Session\AccountInterface
*/
private $currentUser;
/**
* @var \Drupal\Core\Routing\UrlGeneratorInterface
*/
protected $urlGenerator;
/**
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* @param \Drupal\Core\Session\AccountInterface $currentUser
* @param \Drupal\Core\Routing\UrlGeneratorInterface $urlGenerator
* @param \Drupal\Core\Render\RendererInterface $renderer
*/
public function __construct(AccountInterface $currentUser, UrlGeneratorInterface $urlGenerator, RendererInterface $renderer) {
$this->currentUser = $currentUser;
$this->urlGenerator = $urlGenerator;
$this->renderer = $renderer;
}
/**
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
*/
public function onKernelResponse(FilterResponseEvent $event) {
$response = $event
->getResponse();
$request = $event
->getRequest();
if ($response->headers
->has('X-Debug-Token') && NULL !== $this->urlGenerator) {
$response->headers
->set('X-Debug-Token-Link', $this->urlGenerator
->generate('webprofiler.dashboard', [
'profile' => $response->headers
->get('X-Debug-Token'),
]));
}
// Do not capture redirects or modify XML HTTP Requests.
if ($request
->isXmlHttpRequest()) {
return;
}
if ($this->currentUser
->hasPermission('view webprofiler toolbar')) {
$this
->injectToolbar($response);
}
}
/**
* @param \Symfony\Component\HttpFoundation\Response $response
*/
protected function injectToolbar(Response $response) {
$content = $response
->getContent();
$pos = mb_strripos($content, '</body>');
if (FALSE !== $pos) {
if ($token = $response->headers
->get('X-Debug-Token')) {
$loader = [
'#theme' => 'webprofiler_loader',
'#token' => $token,
'#profiler_url' => $this->urlGenerator
->generate('webprofiler.toolbar', [
'profile' => $token,
]),
];
$content = mb_substr($content, 0, $pos) . $this->renderer
->renderRoot($loader) . mb_substr($content, $pos);
$response
->setContent($content);
}
}
}
/**
* @return array
*/
public static function getSubscribedEvents() {
return [
KernelEvents::RESPONSE => [
'onKernelResponse',
-128,
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
WebprofilerEventSubscriber:: |
private | property | ||
WebprofilerEventSubscriber:: |
protected | property | ||
WebprofilerEventSubscriber:: |
protected | property | ||
WebprofilerEventSubscriber:: |
public static | function | ||
WebprofilerEventSubscriber:: |
protected | function | ||
WebprofilerEventSubscriber:: |
public | function | ||
WebprofilerEventSubscriber:: |
public | function |