/**
  * Guess the locale based on the topleveldomain
  *
  * @param Request $request
  *
  * @return bool
  */
 public function guessLocale(Request $request)
 {
     $topLevelDomain = substr(strrchr($request->getHost(), '.'), 1);
     //use topleveldomain as locale
     $locale = $topLevelDomain;
     //see if we have some additional mappings
     if ($topLevelDomain && $this->topleveldomainLocaleMap->getLocale($topLevelDomain)) {
         $locale = $this->topleveldomainLocaleMap->getLocale($topLevelDomain);
     }
     //now validate
     if (false !== $locale && $this->metaValidator->isAllowed($locale)) {
         $this->identifiedLocale = $locale;
         return true;
     }
     return false;
 }
 public function testGetLocale()
 {
     $tldLocaleMap = new TopleveldomainLocaleMap(array('net' => 'de', 'org' => null, 'com' => 'en_US', 'uk' => 'en_GB', 'be' => 'fr_BE'));
     $this->assertEquals('en_GB', $tldLocaleMap->getLocale('uk'));
     $this->assertEquals('en_US', $tldLocaleMap->getLocale('com'));
     $this->assertEquals('de', $tldLocaleMap->getLocale('net'));
     $this->assertEquals(false, $tldLocaleMap->getLocale('fr'));
     $this->assertEquals(false, $tldLocaleMap->getLocale('org'));
     $this->assertEquals('fr_BE', $tldLocaleMap->getLocale('be'));
 }