added support for setting a custom default format in Request::getRequestFormat()
This commit is contained in:
parent
c6818d8bf7
commit
53c7bcf3aa
@ -630,14 +630,16 @@ class Request
|
||||
*
|
||||
* * format defined by the user (with setRequestFormat())
|
||||
* * _format request parameter
|
||||
* * null
|
||||
* * $default
|
||||
*
|
||||
* @param string $default The default format
|
||||
*
|
||||
* @return string The request format
|
||||
*/
|
||||
public function getRequestFormat()
|
||||
public function getRequestFormat($default = 'html')
|
||||
{
|
||||
if (null === $this->format) {
|
||||
$this->format = $this->get('_format', 'html');
|
||||
$this->format = $this->get('_format', $default);
|
||||
}
|
||||
|
||||
return $this->format;
|
||||
|
@ -666,4 +666,17 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
$request->headers->set('Accept-language', 'zh, i-cherokee; q=0.6');
|
||||
$this->assertEquals(array('zh', 'cherokee'), $request->getLanguages());
|
||||
}
|
||||
|
||||
public function testGetRequestFormat()
|
||||
{
|
||||
$request = new Request();
|
||||
$this->assertEquals('html', $request->getRequestFormat());
|
||||
|
||||
$request = new Request();
|
||||
$this->assertEquals(null, $request->getRequestFormat(null));
|
||||
|
||||
$request = new Request();
|
||||
$this->assertEquals(null, $request->setRequestFormat('foo'));
|
||||
$this->assertEquals('foo', $request->getRequestFormat(null));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user