vendor/symfony/symfony/src/Symfony/Bridge/Monolog/Handler/FirePHPHandler.php line 35

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Bridge\Monolog\Handler;
  11. use Monolog\Handler\FirePHPHandler as BaseFirePHPHandler;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
  14. /**
  15.  * FirePHPHandler.
  16.  *
  17.  * @author Jordi Boggiano <j.boggiano@seld.be>
  18.  */
  19. class FirePHPHandler extends BaseFirePHPHandler
  20. {
  21.     private $headers = [];
  22.     /**
  23.      * @var Response
  24.      */
  25.     private $response;
  26.     /**
  27.      * Adds the headers to the response once it's created.
  28.      */
  29.     public function onKernelResponse(FilterResponseEvent $event)
  30.     {
  31.         if (!$event->isMasterRequest()) {
  32.             return;
  33.         }
  34.         $request $event->getRequest();
  35.         if (!preg_match('{\bFirePHP/\d+\.\d+\b}'$request->headers->get('User-Agent'))
  36.             && !$request->headers->has('X-FirePHP-Version')) {
  37.             self::$sendHeaders false;
  38.             $this->headers = [];
  39.             return;
  40.         }
  41.         $this->response $event->getResponse();
  42.         foreach ($this->headers as $header => $content) {
  43.             $this->response->headers->set($header$content);
  44.         }
  45.         $this->headers = [];
  46.     }
  47.     /**
  48.      * {@inheritdoc}
  49.      */
  50.     protected function sendHeader($header$content)
  51.     {
  52.         if (!self::$sendHeaders) {
  53.             return;
  54.         }
  55.         if ($this->response) {
  56.             $this->response->headers->set($header$content);
  57.         } else {
  58.             $this->headers[$header] = $content;
  59.         }
  60.     }
  61.     /**
  62.      * Override default behavior since we check the user agent in onKernelResponse.
  63.      */
  64.     protected function headersAccepted()
  65.     {
  66.         return true;
  67.     }
  68. }