Skip to content

Commit

Permalink
[HttpFoundation] Fixes for PHP 8.1 deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmajor committed Apr 27, 2021
1 parent bc4e440 commit 90e4071
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
18 changes: 9 additions & 9 deletions 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 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']]],
$this->getFormatToMimeTypeMapProvider()
);
}
Expand Down

0 comments on commit 90e4071

Please sign in to comment.