*/ class RedirectListener { protected RedirectMatcher $matcher; protected RedirectBuilder $builder; protected RedirectRepositoryQuery $repository; public function __construct(RedirectMatcher $matcher, RedirectBuilder $builder, RedirectRepositoryQuery $repository) { $this->matcher = $matcher; $this->builder = $builder; $this->repository = $repository; } public function onKernelException(ExceptionEvent $event) { $request = $event->getRequest(); if (!$event->getThrowable() instanceof NotFoundHttpException) { return; } $redirects = $this->repository ->orderBy('.sortOrder') ->where('.isEnabled=1') ->find() ; foreach ($redirects as $redirect) { if ($this->matcher->match($redirect, $event->getRequest()->getUri())) { $event->setResponse($this->builder->buildResponse($redirect, $event->getRequest())); } } } }