Skip to content

Commit

Permalink
Added route check
Browse files Browse the repository at this point in the history
  • Loading branch information
Steveb-p committed Apr 9, 2024
1 parent bd24d6e commit 66f7268
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/bundle/Controller/UserSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -50,7 +50,7 @@ class UserSettingsController extends Controller implements LoggerAwareInterface

private PermissionResolver $permissionResolver;

private RouterInterface $router;
private UrlGeneratorInterface $urlGenerator;

public function __construct(
FormFactory $formFactory,
Expand All @@ -59,7 +59,7 @@ public function __construct(
ValueDefinitionRegistry $valueDefinitionRegistry,
ActionResultHandler $actionResultHandler,
PermissionResolver $permissionResolver,
RouterInterface $router,
UrlGeneratorInterface $urlGenerator,
LoggerInterface $logger = null
) {
$this->formFactory = $formFactory;
Expand All @@ -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();
}

Expand Down Expand Up @@ -154,10 +154,13 @@ public function updateAction(Request $request, UpdateView $view)
return $view;
}

private function routeExists($route, array $routeParameters): bool
/**
* @param array<mixed> $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) {
Expand Down

0 comments on commit 66f7268

Please sign in to comment.