Parsing request language header

This commit is contained in:
Dennis Eichhorn 2017-01-01 15:49:21 +01:00
parent 73d89b7d05
commit c15928bcc9
2 changed files with 37 additions and 1 deletions

View File

@ -139,6 +139,7 @@ class Request extends RequestAbstract
{ {
$this->data = $_GET ?? []; $this->data = $_GET ?? [];
$this->files = $_FILES ?? []; $this->files = $_FILES ?? [];
$this->language = $this->loadRequestLanguage();
if (isset($_SERVER['CONTENT_TYPE'])) { if (isset($_SERVER['CONTENT_TYPE'])) {
if (strpos($_SERVER['CONTENT_TYPE'], 'application/json') !== false) { if (strpos($_SERVER['CONTENT_TYPE'], 'application/json') !== false) {
@ -156,6 +157,15 @@ class Request extends RequestAbstract
$this->uri = $this->uri ?? new Http(Http::getCurrent()); $this->uri = $this->uri ?? new Http(Http::getCurrent());
} }
private function loadRequestLanguage() : string
{
$lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$lang = explode(';', $lang);
$lang = explode('-', $lang[0]);
return $lang[0];
}
/** /**
* Init pseudo request * Init pseudo request
* *
@ -216,6 +226,14 @@ class Request extends RequestAbstract
} }
} }
/**
* {@inheritdoc}
*/
public function getLanguage() : string
{
return $this->language;
}
/** /**
* Create request hashs of current request * Create request hashs of current request
* *

View File

@ -83,13 +83,21 @@ abstract class RequestAbstract implements MessageInterface
protected $path = []; protected $path = [];
/** /**
* Language. * Localization.
* *
* @var Localization * @var Localization
* @since 1.0.0 * @since 1.0.0
*/ */
protected $l11n = null; protected $l11n = null;
/**
* Language.
*
* @var string
* @since 1.0.0
*/
protected $language = '';
/** /**
* Account. * Account.
* *
@ -168,6 +176,16 @@ abstract class RequestAbstract implements MessageInterface
$this->uri = $uri; $this->uri = $uri;
} }
/**
* Get request language.
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
abstract public function getLanguage() : string;
/** /**
* Get request hash. * Get request hash.
* *