src/EventSubscriber/ChatbotSubscriber.php line 20

Open in your IDE?
  1. <?php
  2. // src/EventSubscriber/ChatbotSubscriber.php
  3. namespace App\EventSubscriber;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  6. use Symfony\Component\HttpKernel\KernelEvents;
  7. class ChatbotSubscriber implements EventSubscriberInterface
  8. {
  9.     private $hiddenRoutes;
  10.     public function __construct(array $hiddenRoutes)
  11.     {
  12.         $this->hiddenRoutes $hiddenRoutes;
  13.     }
  14.     public function onKernelResponse(ResponseEvent $event)
  15.     {
  16.         $request $event->getRequest();
  17.         $currentPath $request->getPathInfo();
  18.         if (in_array($currentPath$this->hiddenRoutes)) {
  19.             $response $event->getResponse();
  20.             $content $response->getContent();
  21.             $style '<style>#chatbot-insert { display: none; }</style>';
  22.             $content str_replace('</head>'$style '</head>'$content);
  23.             $response->setContent($content);
  24.         }
  25.     }
  26.     public static function getSubscribedEvents()
  27.     {
  28.         return [
  29.         KernelEvents::RESPONSE => 'onKernelResponse',
  30.         ];
  31.     }
  32. }