Hoa central
Public Member Functions | Protected Attributes | List of all members
Hoa\Locale\Localizer\Http Class Reference
Inheritance diagram for Hoa\Locale\Localizer\Http:

Public Member Functions

 __construct ($headerValue=null)
 
 getLocale ()
 

Protected Attributes

 $_value = null
 

Detailed Description

Class .

Deduce locale from a HTTP request.

Overview: http://www.w3.org/International/articles/language-tags/. Specifications: RFC2822 and RFC3282.

Definition at line 52 of file Http.php.

Constructor & Destructor Documentation

Hoa\Locale\Localizer\Http::__construct (   $headerValue = null)

Constructor.

Parameters
string$headerValueAccept-Language value. If null, will be deduced from the current HTTP request.
Returns
void

Definition at line 70 of file Http.php.

71  {
72  $value = $headerValue ?: HHttp\Runtime::getHeader('accept-language');
73 
74  // Remove CFWS.
75  $this->_value = preg_replace('#\([^\)]+\)|\s#', '', $value);
76 
77  return;
78  }
static getHeader($header)
Definition: Runtime.php:181

Here is the call graph for this function:

Member Function Documentation

Hoa\Locale\Localizer\Http::getLocale ( )

Get locale. Please, see RFC3282 3. The Accept-Language header and RFC2822 3.2.3. Folding white space and comments.

Returns
string

Implements Hoa\Locale\Localizer\Localizer.

Definition at line 87 of file Http.php.

88  {
89  foreach (explode(',', $this->_value) as $language) {
90  $match = preg_match(
91  '#^(?<language>[^;]+)(;q=(?<q>0(?:\.\d{0,3})|1(?:\.0{0,3})))?$#',
92  $language,
93  $matches
94  );
95 
96  if (0 !== $match) {
97  break;
98  }
99  }
100 
101  if (empty($matches)) {
102  return null;
103  }
104 
105  return $matches['language'];
106  }

Member Data Documentation

Hoa\Locale\Localizer\Http::$_value = null
protected

Definition at line 59 of file Http.php.


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