Skip to content

Commit

Permalink
Correctly check for root routes
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Sep 6, 2024
1 parent 9522c37 commit 9f27615
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/Routing/CountryRoutingFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}

Expand All @@ -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;
}
}

0 comments on commit 9f27615

Please sign in to comment.