diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 098ce6d251e04..e737a7e58c832 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -85,7 +85,7 @@ class Request /** * Request body parameters ($_POST). * - * @var InputBag + * @var InputBag|ParameterBag */ public $request; @@ -268,7 +268,7 @@ public function __construct(array $query = [], array $request = [], array $attri */ public function initialize(array $query = [], array $request = [], array $attributes = [], array $cookies = [], array $files = [], array $server = [], $content = null) { - $this->request = new InputBag($request); + $this->request = new ParameterBag($request); $this->query = new InputBag($query); $this->attributes = new ParameterBag($attributes); $this->cookies = new InputBag($cookies); @@ -298,7 +298,9 @@ public static function createFromGlobals() { $request = self::createRequestFromFactory($_GET, $_POST, [], $_COOKIE, $_FILES, $_SERVER); - if (0 === strpos($request->headers->get('CONTENT_TYPE'), 'application/x-www-form-urlencoded') + if ($_POST) { + $request->request = new InputBag($_POST); + } elseif (0 === strpos($request->headers->get('CONTENT_TYPE'), 'application/x-www-form-urlencoded') && \in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), ['PUT', 'DELETE', 'PATCH']) ) { parse_str($request->getContent(), $data); @@ -447,7 +449,7 @@ public function duplicate(array $query = null, array $request = null, array $att $dup->query = new InputBag($query); } if (null !== $request) { - $dup->request = new InputBag($request); + $dup->request = new ParameterBag($request); } if (null !== $attributes) { $dup->attributes = new ParameterBag($attributes); diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index b8c57fc92418e..99cd54884f51c 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -13,6 +13,8 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException; +use Symfony\Component\HttpFoundation\InputBag; +use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; @@ -1255,6 +1257,11 @@ public function testCreateFromGlobals($method) { $normalizedMethod = strtoupper($method); + $_POST = []; + $request = Request::createFromGlobals(); + $this->assertNotInstanceOf(InputBag::class, $request->request); + $this->assertInstanceOf(ParameterBag::class, $request->request); + $_GET['foo1'] = 'bar1'; $_POST['foo2'] = 'bar2'; $_COOKIE['foo3'] = 'bar3'; @@ -1267,6 +1274,8 @@ public function testCreateFromGlobals($method) $this->assertEquals('bar3', $request->cookies->get('foo3'), '::fromGlobals() uses values from $_COOKIE'); $this->assertEquals(['bar4'], $request->files->get('foo4'), '::fromGlobals() uses values from $_FILES'); $this->assertEquals('bar5', $request->server->get('foo5'), '::fromGlobals() uses values from $_SERVER'); + $this->assertInstanceOf(InputBag::class, $request->request); + $this->assertInstanceOf(ParameterBag::class, $request->request); unset($_GET['foo1'], $_POST['foo2'], $_COOKIE['foo3'], $_FILES['foo4'], $_SERVER['foo5']); @@ -1275,6 +1284,8 @@ public function testCreateFromGlobals($method) $request = RequestContentProxy::createFromGlobals(); $this->assertEquals($normalizedMethod, $request->getMethod()); $this->assertEquals('mycontent', $request->request->get('content')); + $this->assertInstanceOf(InputBag::class, $request->request); + $this->assertInstanceOf(ParameterBag::class, $request->request); unset($_SERVER['REQUEST_METHOD'], $_SERVER['CONTENT_TYPE']);