. */ declare(strict_types=1); namespace App\EventListener; use App\Services\LogSystem\EventCommentHelper; use Symfony\Component\EventDispatcher\Attribute\AsEventListener; use Symfony\Component\HttpKernel\Event\RequestEvent; #[AsEventListener] class AddEditCommentRequestListener { public function __construct(private readonly EventCommentHelper $helper) { } public function __invoke(RequestEvent $event) { if (!$event->isMainRequest()) { return; } $request = $event->getRequest(); //Do not add comment if the request is a GET request if ($request->isMethod('GET')) { return; } //Check if the user tries to access a /api/ endpoint, if not skip if (!str_contains($request->getPathInfo(), '/api/')) { return; } //Extract the comment from the query parameter $comment = $request->query->getString('_comment', ''); if ($comment !== '') { $this->helper->setMessage($comment); } } }