Skip to content

[HttpFoundation] Fixes for PHP 8.1 deprecations #40964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 27, 2021
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
18 changes: 9 additions & 9 deletions src/Symfony/Component/HttpFoundation/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ 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 (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);
Expand Down Expand Up @@ -1391,7 +1391,7 @@ public function setRequestFormat($format)
*/
public function getContentType()
{
return $this->getFormat($this->headers->get('CONTENT_TYPE'));
return $this->getFormat($this->headers->get('CONTENT_TYPE', ''));
}

/**
Expand Down Expand Up @@ -1564,7 +1564,7 @@ public function getContent($asResource = false)
*/
public function getETags()
{
return preg_split('/\s*,\s*/', $this->headers->get('if_none_match'), -1, \PREG_SPLIT_NO_EMPTY);
return preg_split('/\s*,\s*/', $this->headers->get('if_none_match', ''), -1, \PREG_SPLIT_NO_EMPTY);
}

/**
Expand Down Expand Up @@ -1790,13 +1790,13 @@ protected function prepareRequestUri()
*/
protected function prepareBaseUrl()
{
$filename = basename($this->server->get('SCRIPT_FILENAME'));
$filename = basename($this->server->get('SCRIPT_FILENAME', ''));

if (basename($this->server->get('SCRIPT_NAME')) === $filename) {
if (basename($this->server->get('SCRIPT_NAME', '')) === $filename) {
$baseUrl = $this->server->get('SCRIPT_NAME');
} elseif (basename($this->server->get('PHP_SELF')) === $filename) {
} elseif (basename($this->server->get('PHP_SELF', '')) === $filename) {
$baseUrl = $this->server->get('PHP_SELF');
} elseif (basename($this->server->get('ORIG_SCRIPT_NAME')) === $filename) {
} elseif (basename($this->server->get('ORIG_SCRIPT_NAME', '')) === $filename) {
$baseUrl = $this->server->get('ORIG_SCRIPT_NAME'); // 1and1 shared hosting compatibility
} else {
// Backtrack up the script_filename to find the portion matching
Expand Down Expand Up @@ -1836,7 +1836,7 @@ protected function prepareBaseUrl()
$truncatedRequestUri = substr($requestUri, 0, $pos);
}

$basename = basename($baseUrl);
$basename = basename($baseUrl ?? '');
if (empty($basename) || !strpos(rawurldecode($truncatedRequestUri), $basename)) {
// no match whatsoever; set it blank
return '';
Expand Down Expand Up @@ -1987,7 +1987,7 @@ private static function createRequestFromFactory(array $query = [], array $reque
*/
public function isFromTrustedProxy()
{
return self::$trustedProxies && IpUtils::checkIp($this->server->get('REMOTE_ADDR'), self::$trustedProxies);
return self::$trustedProxies && IpUtils::checkIp($this->server->get('REMOTE_ADDR', ''), self::$trustedProxies);
}

private function getTrustedValues(int $type, string $ip = null): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
$r->headers->setCookie(new Cookie($str, $str, 0, '/', null, false, false, true, null));
$r->sendHeaders();

setrawcookie($str, $str, 0, '/', null, false, false);
setrawcookie($str, $str, 0, '/', '', false, false);
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ public function testGetFormatFromMimeType($format, $mimeTypes)
public function getFormatToMimeTypeMapProviderWithAdditionalNullFormat()
{
return array_merge(
[[null, [null, 'unexistent-mime-type']]],
[[null, ['unexistent-mime-type']]],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Request::getFormat() does not accept null:

/**
* Gets the format associated with the mime type.
*
* @param string $mimeType The associated mime type
*
* @return string|null The format (null if not found)
*/
public function getFormat($mimeType)

$this->getFormatToMimeTypeMapProvider()
);
}
Expand Down