Skip to content

Commit

Permalink
Merge pull request #74 from luxifer/language-three-parts
Browse files Browse the repository at this point in the history
Language three parts
  • Loading branch information
willdurand committed Nov 21, 2015
2 parents 3712621 + 58d40eb commit a8ce6da
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/Negotiation/AcceptLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

final class AcceptLanguage extends BaseAccept implements AcceptHeader
{
private $basePart;

private $subPart;
private $language;
private $script;
private $region;

public function __construct($value)
{
Expand All @@ -17,10 +17,14 @@ public function __construct($value)
$parts = explode('-', $this->type);

if (2 === count($parts)) {
$this->basePart = $parts[0];
$this->subPart = $parts[1];
$this->language = $parts[0];
$this->region = $parts[1];
} elseif (1 === count($parts)) {
$this->basePart = $parts[0];
$this->language = $parts[0];
} elseif (3 === count($parts)) {
$this->language = $parts[0];
$this->script = $parts[1];
$this->region = $parts[2];
} else {
// TODO: this part is never reached...
throw new InvalidLanguage();
Expand All @@ -32,14 +36,14 @@ public function __construct($value)
*/
public function getSubPart()
{
return $this->subPart;
return $this->region;
}

/**
* @return string
*/
public function getBasePart()
{
return $this->basePart;
return $this->language;
}
}
1 change: 1 addition & 0 deletions tests/Negotiation/Tests/LanguageNegotiatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static function dataProviderForTestGetBest()
array('en; q=0.1, fr; q=0.4, bu; q=1.0', array('en', 'fr'), 'fr'),
array('en; q=0.1, fr; q=0.4, fu; q=0.9, de; q=0.2', array('en', 'fu'), 'fu'),
array('', array('en', 'fu'), new InvalidArgument('The header string should not be empty.')),
array('fr, zh-Hans-CN;q=0.3', array('fr'), 'fr'),
);
}

Expand Down

0 comments on commit a8ce6da

Please sign in to comment.