Fix some PHP 8.1 deprecation warnings

* Fix passing null to str_replace and preg_replace in HttpSocket
* Fix dynamic props usage in ModelValidator
* Fix passing null to rawurlencode in CakeRoute
This commit is contained in:
Juan Cruz Vincenti 2024-01-09 16:35:08 -03:00 committed by Kamil Wylegala
parent 2eeb1f6476
commit 84cfdfb0c3
3 changed files with 6 additions and 5 deletions

View file

@ -31,6 +31,7 @@ App::uses('Hash', 'Utility');
* @package Cake.Model
* @link https://book.cakephp.org/2.0/en/data-validation.html
*/
#[\AllowDynamicProperties]
class ModelValidator implements ArrayAccess, IteratorAggregate, Countable {
/**

View file

@ -720,7 +720,7 @@ class HttpSocket extends CakeSocket {
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(
@ -732,16 +732,16 @@ class HttpSocket extends CakeSocket {
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 === '/*') {

View file

@ -498,7 +498,7 @@ class CakeRoute {
}
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();