/**
  * @covers Kunstmaan\LanguageChooserBundle\LocaleGuesser\UrlLocaleGuesser::guessLocale
  */
 public function testInvalidLocaleFound()
 {
     $this->metaValidator->expects($this->once())->method('isAllowed')->will($this->returnValue(false));
     $this->request->expects($this->once())->method('getPathInfo')->will($this->returnValue('/en/another-path'));
     $this->assertFalse($this->object->guessLocale($this->request));
     $this->assertEquals(null, $this->object->getIdentifiedLocale());
 }
 /**
  * Retrieve from cookie
  *
  * @param Request $request Request
  *
  * @return bool
  */
 public function guessLocale(Request $request)
 {
     if ($request->cookies->has($this->localeCookieName) && $this->metaValidator->isAllowed($request->cookies->get($this->localeCookieName))) {
         $this->identifiedLocale = $request->cookies->get($this->localeCookieName);
         return true;
     }
     return false;
 }
 /**
  * Guess the locale based on the subdomain
  *
  * @param Request $request
  *
  * @return bool
  */
 public function guessLocale(Request $request)
 {
     $subdomain = strstr($request->getHost(), '.', true);
     if ('_' !== $this->regionSeparator) {
         $subdomain = str_replace($this->regionSeparator, '_', $subdomain);
     }
     if (false !== $subdomain && $this->metaValidator->isAllowed($subdomain)) {
         $this->identifiedLocale = $subdomain;
         return true;
     }
     return false;
 }
 /**
  * Guess the locale based on the session variable
  *
  * @param Request $request
  *
  * @return boolean
  */
 public function guessLocale(Request $request)
 {
     if ($this->session->has($this->sessionVariable)) {
         $locale = $this->session->get($this->sessionVariable);
         if (!$this->metaValidator->isAllowed($locale)) {
             return false;
         }
         $this->identifiedLocale = $this->session->get($this->sessionVariable);
         return true;
     }
     return false;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }