getLanguageCookie() public static method

Retrieve the user-selected language from a cookie.
public static getLanguageCookie ( ) : string | null
return string | null The selected language or null if unset.
Ejemplo n.º 1
0
 /**
  * Test SimpleSAML\Locale\Language::getLanguageCookie().
  */
 public function testGetLanguageCookie()
 {
     // test it works when no cookie is set
     \SimpleSAML_Configuration::loadFromArray(array(), '', 'simplesaml');
     $this->assertNull(Language::getLanguageCookie());
     // test that it works fine with defaults
     \SimpleSAML_Configuration::loadFromArray(array(), '', 'simplesaml');
     $_COOKIE['language'] = 'en';
     $this->assertEquals('en', Language::getLanguageCookie());
     // test that it works with non-defaults
     \SimpleSAML_Configuration::loadFromArray(array('language.available' => array('en', 'es', 'nn'), 'language.cookie.name' => 'xyz'), '', 'simplesaml');
     $_COOKIE['xyz'] = 'Es';
     // test values are converted to lowercase too
     $this->assertEquals('es', Language::getLanguageCookie());
 }
Ejemplo n.º 2
0
 /**
  * @return null|string
  * @deprecated This method will be removed in SSP 2.0. Please use \SimpleSAML\Locale\Language::getLanguageCookie()
  * instead.
  */
 public static function getLanguageCookie()
 {
     return \SimpleSAML\Locale\Language::getLanguageCookie();
 }
Ejemplo n.º 3
0
 /**
  * This method will return the language selected by the user, or the default language. It looks first for a cached
  * language code, then checks for a language cookie, then it tries to calculate the preferred language from HTTP
  * headers.
  *
  * @return string The language selected by the user according to the processing rules specified, or the default
  * language in any other case.
  */
 public function getLanguage()
 {
     // language is set in object
     if (isset($this->language)) {
         return $this->language;
     }
     // run custom getLanguage function if defined
     if (isset($this->customFunction) && is_callable($this->customFunction)) {
         $customLanguage = call_user_func($this->customFunction, $this);
         if ($customLanguage !== null && $customLanguage !== false) {
             return $customLanguage;
         }
     }
     // language is provided in a stored cookie
     $languageCookie = Language::getLanguageCookie();
     if ($languageCookie !== null) {
         $this->language = $languageCookie;
         return $languageCookie;
     }
     // check if we can find a good language from the Accept-Language HTTP header
     $httpLanguage = $this->getHTTPLanguage();
     if ($httpLanguage !== null) {
         return $httpLanguage;
     }
     // language is not set, and we get the default language from the configuration
     return $this->getDefaultLanguage();
 }