Skip to content

Commit 3690740

Browse files
Merge branch '7.4' into 8.0
* 7.4: [HttpFoundation] Improve logic in Request::createFromGlobals()
2 parents afcb9ed + bd1af1e commit 3690740

File tree

2 files changed

+8
-21
lines changed

2 files changed

+8
-21
lines changed

Request.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -285,21 +285,18 @@ public function initialize(array $query = [], array $request = [], array $attrib
285285
*/
286286
public static function createFromGlobals(): static
287287
{
288-
$request = self::createRequestFromFactory($_GET, $_POST, [], $_COOKIE, $_FILES, $_SERVER);
289-
290-
if (!\in_array($request->server->get('REQUEST_METHOD', 'GET'), ['PUT', 'DELETE', 'PATCH', 'QUERY'], true)) {
291-
return $request;
288+
if (!\in_array($_SERVER['REQUEST_METHOD'] ?? null, ['PUT', 'DELETE', 'PATCH', 'QUERY'], true)) {
289+
return self::createRequestFromFactory($_GET, $_POST, [], $_COOKIE, $_FILES, $_SERVER);
292290
}
293291

294292
try {
295293
[$post, $files] = request_parse_body();
296-
297-
$request->request->add($post);
298-
$request->files->add($files);
299294
} catch (\RequestParseBodyException) {
295+
$post = $_POST;
296+
$files = $_FILES;
300297
}
301298

302-
return $request;
299+
return self::createRequestFromFactory($_GET, $post, [], $_COOKIE, $files, $_SERVER);
303300
}
304301

305302
/**
@@ -1496,10 +1493,8 @@ public function getProtocolVersion(): ?string
14961493
*/
14971494
public function getContent(bool $asResource = false)
14981495
{
1499-
$currentContentIsResource = \is_resource($this->content);
1500-
1501-
if (true === $asResource) {
1502-
if ($currentContentIsResource) {
1496+
if ($asResource) {
1497+
if (\is_resource($this->content)) {
15031498
rewind($this->content);
15041499

15051500
return $this->content;
@@ -1519,7 +1514,7 @@ public function getContent(bool $asResource = false)
15191514
return fopen('php://input', 'r');
15201515
}
15211516

1522-
if ($currentContentIsResource) {
1517+
if (\is_resource($this->content)) {
15231518
rewind($this->content);
15241519

15251520
return stream_get_contents($this->content);

Tests/RequestTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3001,14 +3001,6 @@ public static function providePreferredFormatRfc9110(): iterable
30013001
}
30023002
}
30033003

3004-
class RequestContentProxy extends Request
3005-
{
3006-
public function getContent($asResource = false)
3007-
{
3008-
return http_build_query(['content' => 'mycontent'], '', '&');
3009-
}
3010-
}
3011-
30123004
class NewRequest extends Request
30133005
{
30143006
public function getFoo()

0 commit comments

Comments
 (0)