[HttpFoundation] Added Request::getEncodings() method

This commit is contained in:
Mark Sonnabaum 2013-06-03 09:39:44 -05:00
parent f26c2b9deb
commit 28a8443a5f
2 changed files with 33 additions and 0 deletions

View File

@ -218,6 +218,7 @@ class Request
$this->content = $content;
$this->languages = null;
$this->charsets = null;
$this->encodings = null;
$this->acceptableContentTypes = null;
$this->pathInfo = null;
$this->requestUri = null;
@ -386,6 +387,7 @@ class Request
}
$dup->languages = null;
$dup->charsets = null;
$dup->encodings = null;
$dup->acceptableContentTypes = null;
$dup->pathInfo = null;
$dup->requestUri = null;
@ -1444,6 +1446,21 @@ class Request
return $this->charsets = array_keys(AcceptHeader::fromString($this->headers->get('Accept-Charset'))->all());
}
/**
* Gets a list of encodings acceptable by the client browser.
*
* @return array List of encodings in preferable order
*
* @api
*/
public function getEncodings()
{
if (null !== $this->encodings) {
return $this->encodings;
}
return $this->encodings = array_keys(AcceptHeader::fromString($this->headers->get('Accept-Encoding'))->all());
}
/**
* Gets a list of content types acceptable by the client browser
*

View File

@ -1122,6 +1122,22 @@ class RequestTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(array('ISO-8859-1', 'utf-8', '*'), $request->getCharsets());
}
public function testGetEncodings()
{
$request = new Request();
$this->assertEquals(array(), $request->getEncodings());
$request->headers->set('Accept-Encoding', 'gzip,deflate,sdch');
$this->assertEquals(array(), $request->getEncodings()); // testing caching
$request = new Request();
$request->headers->set('Accept-Encoding', 'gzip,deflate,sdch');
$this->assertEquals(array('gzip', 'deflate', 'sdch'), $request->getEncodings());
$request = new Request();
$request->headers->set('Accept-Encoding', 'gzip;q=0.4,deflate;q=0.9,compress;q=0.7');
$this->assertEquals(array('deflate', 'compress', 'gzip'), $request->getEncodings());
}
public function testGetAcceptableContentTypes()
{
$request = new Request();