From 027482628e0485588171f9ac98f6c9d0c72a3d20 Mon Sep 17 00:00:00 2001 From: Danny van Wijk Date: Tue, 8 Oct 2024 15:54:25 +0200 Subject: [PATCH] Improve domain based locale router performance --- .../Router/DomainBasedLocaleRouter.php | 50 +------------------ 1 file changed, 1 insertion(+), 49 deletions(-) diff --git a/src/Kunstmaan/MultiDomainBundle/Router/DomainBasedLocaleRouter.php b/src/Kunstmaan/MultiDomainBundle/Router/DomainBasedLocaleRouter.php index 4a3a872192..d4a8159127 100644 --- a/src/Kunstmaan/MultiDomainBundle/Router/DomainBasedLocaleRouter.php +++ b/src/Kunstmaan/MultiDomainBundle/Router/DomainBasedLocaleRouter.php @@ -9,14 +9,10 @@ use Symfony\Component\Routing\Generator\UrlGenerator; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Matcher\UrlMatcher; -use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; class DomainBasedLocaleRouter extends SlugRouter { - /** @var RouteCollection */ - protected $routeCollectionMultiLanguage; - /** * @var array|null */ @@ -172,17 +168,6 @@ private function getReverseLocaleMap(): array */ public function getRouteCollection(): RouteCollection { - if (($this->otherSite && $this->isMultiLanguage($this->otherSite['host'])) || (!$this->otherSite && $this->isMultiLanguage())) { - if (!$this->routeCollectionMultiLanguage) { - $this->routeCollectionMultiLanguage = new RouteCollection(); - - $this->addMultiLangPreviewRoute(); - $this->addMultiLangSlugRoute(); - } - - return $this->routeCollectionMultiLanguage; - } - if (!$this->routeCollection) { $this->routeCollection = new RouteCollection(); @@ -202,39 +187,6 @@ protected function addSlugRoute() $this->addRoute('_slug', $routeParameters); } - /** - * Add the slug route to the route collection - */ - protected function addMultiLangPreviewRoute() - { - $routeParameters = $this->getPreviewRouteParameters(); - $this->addMultiLangRoute('_slug_preview', $routeParameters); - } - - /** - * Add the slug route to the route collection multilanguage - */ - protected function addMultiLangSlugRoute() - { - $routeParameters = $this->getSlugRouteParameters(); - $this->addMultiLangRoute('_slug', $routeParameters); - } - - /** - * @param string $name - */ - protected function addMultiLangRoute($name, array $parameters = []) - { - $this->routeCollectionMultiLanguage->add( - $name, - new Route( - $parameters['path'], - $parameters['defaults'], - $parameters['requirements'] - ) - ); - } - /** * Return slug route parameters * @@ -258,7 +210,7 @@ protected function getSlugRouteParameters() // If other site provided and multilingual, get the locales from the host config. if ($this->otherSite && $this->isMultiLanguage($this->otherSite['host'])) { $locales = $this->getHostLocales(); - } elseif ($this->isMultiLanguage() && !$this->otherSite) { + } elseif (!$this->otherSite && $this->isMultiLanguage()) { $locales = $this->getFrontendLocales(); }