Skip to content
Snippets Groups Projects
Commit 8fc2be4f authored by Jaime Perez Crespo's avatar Jaime Perez Crespo
Browse files

Enhance the documentation for SimpleSAML\Locale\Language. Move all the...

Enhance the documentation for SimpleSAML\Locale\Language. Move all the configuration properties to the constructor, instead of the methods.
parent 486bd878
No related branches found
No related tags found
No related merge requests found
...@@ -20,10 +20,40 @@ class Language ...@@ -20,10 +20,40 @@ class Language
*/ */
private static $defaultLanguageMap = array('nb' => 'no'); private static $defaultLanguageMap = array('nb' => 'no');
private $configuration = null; /**
private $availableLanguages = array('en'); * The configuration to use.
*
* @var \SimpleSAML_Configuration
*/
private $configuration;
/**
* An array holding a list of languages available.
*
* @var array
*/
private $availableLanguages;
/**
* The language currently in use.
*
* @var null|string
*/
private $language = null; private $language = null;
/**
* The language to use by default.
*
* @var string
*/
private $defaultLanguage;
/**
* An array holding a list of languages that are written from right to left.
*
* @var array
*/
private $rtlLanguages;
/** /**
* HTTP GET language parameter name. * HTTP GET language parameter name.
...@@ -39,10 +69,11 @@ class Language ...@@ -39,10 +69,11 @@ class Language
public function __construct(\SimpleSAML_Configuration $configuration) public function __construct(\SimpleSAML_Configuration $configuration)
{ {
$this->configuration = $configuration; $this->configuration = $configuration;
$this->availableLanguages = $this->configuration->getArray('language.available', array('en')); $this->availableLanguages = $this->configuration->getArray('language.available', array('en'));
$this->defaultLanguage = $this->configuration->getString('language.default', 'en');
$this->languageParameterName = $this->configuration->getString('language.parameter.name', 'language'); $this->languageParameterName = $this->configuration->getString('language.parameter.name', 'language');
$this->customFunction = $this->configuration->getArray('language.get_language_function', null);
$this->rtlLanguages = $this->configuration->getArray('language.rtl', array());
if (isset($_GET[$this->languageParameterName])) { if (isset($_GET[$this->languageParameterName])) {
$this->setLanguage( $this->setLanguage(
$_GET[$this->languageParameterName], $_GET[$this->languageParameterName],
...@@ -86,10 +117,9 @@ class Language ...@@ -86,10 +117,9 @@ class Language
} }
// run custom getLanguage function if defined // run custom getLanguage function if defined
$customFunction = $this->configuration->getArray('language.get_language_function', null); if (isset($this->customFunction)) {
if (isset($customFunction)) {
assert('is_callable($customFunction)'); assert('is_callable($customFunction)');
$customLanguage = call_user_func($customFunction, $this); $customLanguage = call_user_func($this->customFunction, $this);
if ($customLanguage !== null && $customLanguage !== false) { if ($customLanguage !== null && $customLanguage !== false) {
return $customLanguage; return $customLanguage;
} }
...@@ -174,14 +204,15 @@ class Language ...@@ -174,14 +204,15 @@ class Language
*/ */
public function getDefaultLanguage() public function getDefaultLanguage()
{ {
return $this->configuration->getString('language.default', 'en'); return $this->defaultLanguage;
} }
/** /**
* Return a list of all languages available. * Return an indexed list of all languages available.
* *
* @return array An array holding all the languages available. * @return array An array holding all the languages available as the keys of the array. The value for each key is
* true in case that the language specified by that key is currently active, or false otherwise.
*/ */
public function getLanguageList() public function getLanguageList()
{ {
...@@ -195,15 +226,14 @@ class Language ...@@ -195,15 +226,14 @@ class Language
/** /**
* Check whether a language is right-to-left or not. * Check whether a language is written from the right to the left or not.
* *
* @return boolean True if the language is right-to-left, false otherwise. * @return boolean True if the language is right-to-left, false otherwise.
*/ */
public function isLanguageRTL() public function isLanguageRTL()
{ {
$rtlLanguages = $this->configuration->getArray('language.rtl', array());
$thisLang = $this->getLanguage(); $thisLang = $this->getLanguage();
if (in_array($thisLang, $rtlLanguages)) { if (in_array($thisLang, $this->rtlLanguages)) {
return true; return true;
} }
return false; return false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment