Skip to content

Commit d8df64c

Browse files
authored
Merge pull request #86 from neural-wetware/strict_media_types
Add $strict parameter to getBest()
2 parents bc81429 + 56f51ee commit d8df64c

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/Negotiation/AbstractNegotiator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ abstract class AbstractNegotiator
1313
*
1414
* @return AcceptHeader|null best matching type
1515
*/
16-
public function getBest($header, array $priorities)
16+
public function getBest($header, array $priorities, $strict = false)
1717
{
1818
if (empty($priorities)) {
1919
throw new InvalidArgument('A set of server priorities should be given.');
@@ -33,7 +33,9 @@ public function getBest($header, array $priorities)
3333
try {
3434
$acceptedHeaders[] = $this->acceptFactory($h);
3535
} catch (Exception\Exception $e) {
36-
// silently skip in case of invalid headers coming in from a client
36+
if ($strict) {
37+
throw $e;
38+
}
3739
}
3840
}
3941
$acceptedPriorities = array();

tests/Negotiation/Tests/NegotiatorTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ public function testGetBestRespectsQualityOfSource()
104104
$this->assertEquals('text/plain', $accept->getType());
105105
}
106106

107+
/**
108+
* @expectedException Negotiation\Exception\InvalidMediaType
109+
*/
110+
public function testGetBestInvalidMediaType()
111+
{
112+
$header = 'sdlfkj20ff; wdf';
113+
$priorities = array('foo/qwer');
114+
115+
$this->negotiator->getBest($header, $priorities, true);
116+
}
117+
107118
/**
108119
* @dataProvider dataProviderForTestParseHeader
109120
*/

0 commit comments

Comments
 (0)