/** * Guess the locale based on the domain * * @param Request $request * * @return bool */ public function guessLocale(Request $request) { $domainParts = array_reverse(explode('.', $request->getHost())); $domain = null; foreach ($domainParts as $domainPart) { if (null === $domain) { $domain = $domainPart; } else { $domain = $domainPart . '.' . $domain; } if (($locale = $this->domainLocaleMap->getLocale($domain)) && $this->metaValidator->isAllowed($locale)) { $this->identifiedLocale = $locale; return true; } } return false; }
public function testGetLocale() { $domainLocaleMap = new DomainLocaleMap(array('sub.dutchversion.be' => 'en_BE', 'dutchversion.be' => 'nl_BE', 'spanishversion.be' => null, 'frenchversion.be' => 'fr_BE')); $this->assertEquals('en_BE', $domainLocaleMap->getLocale('sub.dutchversion.be')); $this->assertEquals('nl_BE', $domainLocaleMap->getLocale('dutchversion.be')); $this->assertEquals(false, $domainLocaleMap->getLocale('spanishversion.be')); $this->assertEquals(false, $domainLocaleMap->getLocale('unknown.be')); $this->assertEquals('fr_BE', $domainLocaleMap->getLocale('frenchversion.be')); }