Skip to content

Commit

Permalink
Fix some PHP 8.1 deprecation warnings
Browse files Browse the repository at this point in the history
* Fix passing null to str_replace and preg_replace in HttpSocket
* Fix dynamic props usage in ModelValidator
* Fix passing null to rawurlencode in CakeRoute
  • Loading branch information
Juan Cruz Vincenti committed Jan 10, 2024
1 parent 2eeb1f6 commit 2362fa2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/Cake/Model/ModelValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* @package Cake.Model
* @link https://book.cakephp.org/2.0/en/data-validation.html
*/
#[\AllowDynamicProperties]
class ModelValidator implements ArrayAccess, IteratorAggregate, Countable {

/**
Expand Down
8 changes: 4 additions & 4 deletions lib/Cake/Network/Http/HttpSocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ protected function _buildUri($uri = array(), $uriTemplate = '%scheme://%user:%pa
return false;
}

$uri['path'] = preg_replace('/^\//', null, $uri['path']);
$uri['path'] = preg_replace('/^\//', '', $uri['path']);
$uri['query'] = http_build_query($uri['query'], '', '&');
$uri['query'] = rtrim($uri['query'], '=');
$stripIfEmpty = array(
Expand All @@ -732,16 +732,16 @@ protected function _buildUri($uri = array(), $uriTemplate = '%scheme://%user:%pa

foreach ($stripIfEmpty as $key => $strip) {
if (empty($uri[$key])) {
$uriTemplate = str_replace($strip, null, $uriTemplate);
$uriTemplate = str_replace($strip, '', $uriTemplate);
}
}

$defaultPorts = array('http' => 80, 'https' => 443);
if (array_key_exists($uri['scheme'], $defaultPorts) && $defaultPorts[$uri['scheme']] == $uri['port']) {
$uriTemplate = str_replace(':%port', null, $uriTemplate);
$uriTemplate = str_replace(':%port', '', $uriTemplate);
}
foreach ($uri as $property => $value) {
$uriTemplate = str_replace('%' . $property, $value, $uriTemplate);
$uriTemplate = str_replace('%' . $property, (string)$value, $uriTemplate);
}

if ($uriTemplate === '/*') {
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Routing/Route/CakeRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ protected function _writeUrl($params) {
}

if (is_array($params['pass'])) {
$params['pass'] = implode('/', array_map('rawurlencode', $params['pass']));
$params['pass'] = implode('/', array_map(fn($param) => rawurlencode((string)$param), $params['pass']));
}

$namedConfig = Router::namedConfig();
Expand Down

0 comments on commit 2362fa2

Please sign in to comment.