vendor/symfony/monolog-bridge/Handler/FirePHPHandler.php line 33

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\ResponseEvent;
  14. /**
  15.  * FirePHPHandler.
  16.  *
  17.  * @author Jordi Boggiano <j.boggiano@seld.be>
  18.  *
  19.  * @final
  20.  */
  21. class FirePHPHandler extends BaseFirePHPHandler
  22. {
  23.     private array $headers = [];
  24.     private ?Response $response null;
  25.     /**
  26.      * Adds the headers to the response once it's created.
  27.      */
  28.     public function onKernelResponse(ResponseEvent $event): void
  29.     {
  30.         if (!$event->isMainRequest()) {
  31.             return;
  32.         }
  33.         $request $event->getRequest();
  34.         if (!preg_match('{\bFirePHP/\d+\.\d+\b}'$request->headers->get('User-Agent'''))
  35.             && !$request->headers->has('X-FirePHP-Version')) {
  36.             self::$sendHeaders false;
  37.             $this->headers = [];
  38.             return;
  39.         }
  40.         $this->response $event->getResponse();
  41.         foreach ($this->headers as $header => $content) {
  42.             $this->response->headers->set($header$content);
  43.         }
  44.         $this->headers = [];
  45.     }
  46.     protected function sendHeader($header$content): void
  47.     {
  48.         if (!self::$sendHeaders) {
  49.             return;
  50.         }
  51.         if (null !== $this->response) {
  52.             $this->response->headers->set($header$content);
  53.         } else {
  54.             $this->headers[$header] = $content;
  55.         }
  56.     }
  57.     /**
  58.      * Override default behavior since we check the user agent in onKernelResponse.
  59.      */
  60.     protected function headersAccepted(): bool
  61.     {
  62.         return true;
  63.     }
  64. }