<?php
// src/EventSubscriber/ChatbotSubscriber.php
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class ChatbotSubscriber implements EventSubscriberInterface
{
private $hiddenRoutes;
public function __construct(array $hiddenRoutes)
{
$this->hiddenRoutes = $hiddenRoutes;
}
public function onKernelResponse(ResponseEvent $event)
{
$request = $event->getRequest();
$currentPath = $request->getPathInfo();
if (in_array($currentPath, $this->hiddenRoutes)) {
$response = $event->getResponse();
$content = $response->getContent();
$style = '<style>#chatbot-insert { display: none; }</style>';
$content = str_replace('</head>', $style . '</head>', $content);
$response->setContent($content);
}
}
public static function getSubscribedEvents()
{
return [
KernelEvents::RESPONSE => 'onKernelResponse',
];
}
}