Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Symfony/Component/HttpFoundation/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,8 @@ public function __toString()
*/
public function overrideGlobals()
{
$this->server->set('QUERY_STRING', static::normalizeQueryString(http_build_query($this->query->all(), null, '&')));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably be $_SERVER['QUERY_STRING'] = static::... instead (and moved after the main $_SERVER assignation). But I don't see why this would be needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A use case is when you want to get the current URI without some GET parameters:

$request->query->remove('nonce');
$redirectUri = $request->getUri();

I code it like this at the first position because getUri() uses getQueryString() that gets the query string from $this->server.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabpot does this need something else?


$_GET = $this->query->all();
$_POST = $this->request->all();
$_SERVER = $this->server->all();
Expand Down
9 changes: 9 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,15 @@ public function testOverrideGlobals()

$this->assertArrayHasKey('HTTP_X_FORWARDED_PROTO', $_SERVER);

$request->initialize(array('foo' => 'bar', 'baz' => 'foo'));
$request->query->remove('baz');

$request->overrideGlobals();

$this->assertEquals(array('foo' => 'bar'), $_GET);
$this->assertEquals('foo=bar', $_SERVER['QUERY_STRING']);
$this->assertEquals('foo=bar', $request->server->get('QUERY_STRING'));

// restore initial $_SERVER array
$_SERVER = $server;
}
Expand Down