From 9f27615e4992a803051ba41ca7c1722208f96a72 Mon Sep 17 00:00:00 2001 From: Andreas Schempp Date: Fri, 6 Sep 2024 10:00:13 +0200 Subject: [PATCH] Correctly check for root routes --- src/Routing/CountryRoutingFilter.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Routing/CountryRoutingFilter.php b/src/Routing/CountryRoutingFilter.php index 57e21cd..d75302b 100644 --- a/src/Routing/CountryRoutingFilter.php +++ b/src/Routing/CountryRoutingFilter.php @@ -8,6 +8,7 @@ use Doctrine\DBAL\Connection; use Symfony\Cmf\Component\Routing\NestedMatcher\RouteFilterInterface; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; use Terminal42\Geoip2CountryBundle\CountryProvider; @@ -30,13 +31,7 @@ public function filter(RouteCollection $collection, Request $request): RouteColl foreach ($collection as $name => $route) { $pageModel = $route->getDefault('pageModel'); - if ( - !$pageModel instanceof PageModel - || ( - !str_ends_with($name, '.root') - && !str_ends_with($name, '.fallback') - ) - ) { + if (!$pageModel instanceof PageModel || !$this->isRootRoute($name, $route)) { continue; } @@ -62,4 +57,17 @@ private function getPagesForCountry(string $country): array|null return $result ? array_map('intval', explode(',', (string) $result)) : null; } + + private function isRootRoute(string $name, Route $route): bool + { + if (str_ends_with($name, '.fallback')) { + return true; + } + + if (str_ends_with($name, '.root') && '/' === $route->getPath()) { + return true; + } + + return false; + } }