ILIAS  trunk Revision v11.0_alpha-1731-gff9cd7e2bd3
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilHttpRequestsLanguageDetector Class Reference

Class ilHttpRequestsLanguageDetector. More...

+ Inheritance diagram for ilHttpRequestsLanguageDetector:
+ Collaboration diagram for ilHttpRequestsLanguageDetector:

Public Member Functions

 __construct (string $header_value)
 
 getIso2LanguageCode ()
 Returns the detected ISO2 language code. More...
 

Protected Attributes

string $header_value
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilHttpRequestsLanguageDetector::__construct ( string  $header_value)

Definition at line 30 of file class.ilHttpRequestsLanguageDetector.php.

References $header_value.

31  {
32  $this->header_value = $header_value;
33  }

Member Function Documentation

◆ getIso2LanguageCode()

ilHttpRequestsLanguageDetector::getIso2LanguageCode ( )

Returns the detected ISO2 language code.

Exceptions
ilLanguageException

Implements ilLanguageDetector.

Definition at line 39 of file class.ilHttpRequestsLanguageDetector.php.

References $lang.

39  : string
40  {
41  if (strlen($this->header_value)) {
42  $matches = array();
43  // Format: de,de-DE;q=0.8,en-US;q=0.6,en;q=0.4
44  preg_match_all("/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i", $this->header_value, $matches);
45  if (count($matches[1])) {
46  $langs = array_combine($matches[1], $matches[4]);
47  foreach ($langs as $lang => $val) {
48  if ($val === '') {
49  $langs[$lang] = 1;
50  }
51  }
52  arsort($langs, SORT_NUMERIC);
53 
54  $keys = array_keys($langs);
55  if (isset($keys[0])) {
56  return substr($keys[0], 0, 2);
57  }
58  }
59  }
60 
61  throw new ilLanguageException("Could not extract any language information from request.");
62  }
Class for language related exception handling in ILIAS.
$lang
Definition: xapiexit.php:25

Field Documentation

◆ $header_value

string ilHttpRequestsLanguageDetector::$header_value
protected

Definition at line 28 of file class.ilHttpRequestsLanguageDetector.php.

Referenced by __construct().


The documentation for this class was generated from the following file: