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 259ccee
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/Routing/CountryRoutingFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

namespace Terminal42\Geoip2CountryBundle\Routing;

use Contao\CoreBundle\ServiceAnnotation\Page;
use Contao\PageModel;
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 +32,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 +58,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 259ccee

Please sign in to comment.