From 1d43007f3c92ddc97ee90c4b21ee50cd15b41966 Mon Sep 17 00:00:00 2001 From: Daniel Wehner Date: Tue, 28 Feb 2017 18:22:29 +0000 Subject: [PATCH] Provide less state in getRequestFormat --- src/Symfony/Component/HttpFoundation/Request.php | 4 ++-- src/Symfony/Component/HttpFoundation/Tests/RequestTest.php | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 697bc6c3c3..d659d188ea 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -1382,10 +1382,10 @@ class Request public function getRequestFormat($default = 'html') { if (null === $this->format) { - $this->format = $this->get('_format', $default); + $this->format = $this->get('_format'); } - return $this->format; + return null === $this->format ? $default : $this->format; } /** diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index 9000eb622b..2b852f5956 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -1401,6 +1401,11 @@ class RequestTest extends TestCase $request = new Request(); $this->assertEquals('html', $request->getRequestFormat()); + // Ensure that setting different default values over time is possible, + // aka. setRequestFormat determines the state. + $this->assertEquals('json', $request->getRequestFormat('json')); + $this->assertEquals('html', $request->getRequestFormat('html')); + $request = new Request(); $this->assertNull($request->getRequestFormat(null));