From 66f7268bffe3eebb9407aac38eddf4ee9463f1d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Tue, 9 Apr 2024 12:16:42 +0200 Subject: [PATCH] Added route check --- src/bundle/Controller/UserSettingsController.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/bundle/Controller/UserSettingsController.php b/src/bundle/Controller/UserSettingsController.php index a5d2225..26b0cc4 100644 --- a/src/bundle/Controller/UserSettingsController.php +++ b/src/bundle/Controller/UserSettingsController.php @@ -27,7 +27,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Exception\ExceptionInterface as RouteExceptionInterface; -use Symfony\Component\Routing\RouterInterface; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; class UserSettingsController extends Controller implements LoggerAwareInterface { @@ -50,7 +50,7 @@ class UserSettingsController extends Controller implements LoggerAwareInterface private PermissionResolver $permissionResolver; - private RouterInterface $router; + private UrlGeneratorInterface $urlGenerator; public function __construct( FormFactory $formFactory, @@ -59,7 +59,7 @@ public function __construct( ValueDefinitionRegistry $valueDefinitionRegistry, ActionResultHandler $actionResultHandler, PermissionResolver $permissionResolver, - RouterInterface $router, + UrlGeneratorInterface $urlGenerator, LoggerInterface $logger = null ) { $this->formFactory = $formFactory; @@ -68,7 +68,7 @@ public function __construct( $this->valueDefinitionRegistry = $valueDefinitionRegistry; $this->actionResultHandler = $actionResultHandler; $this->permissionResolver = $permissionResolver; - $this->router = $router; + $this->urlGenerator = $urlGenerator; $this->logger = $logger ?? new NullLogger(); } @@ -154,10 +154,13 @@ public function updateAction(Request $request, UpdateView $view) return $view; } - private function routeExists($route, array $routeParameters): bool + /** + * @param array $routeParameters + */ + private function routeExists(string $route, array $routeParameters): bool { try { - $this->router->generate($route, $routeParameters); + $this->urlGenerator->generate($route, $routeParameters); return true; } catch (RouteExceptionInterface $e) {