From c66a2f7aebdd5a6ebdb967c44f37018e61991d8c Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 13 Oct 2023 11:16:49 +0200 Subject: [PATCH] [Cache][VarExporter] Fix proxy generation to deal with edgy behaviors of internal classes --- src/Symfony/Component/Cache/Traits/Redis6Proxy.php | 8 ++++---- .../Component/Cache/Traits/RedisCluster6Proxy.php | 8 ++++---- src/Symfony/Component/Cache/Traits/RelayProxy.php | 8 ++++---- src/Symfony/Component/Cache/composer.json | 2 +- src/Symfony/Component/VarExporter/ProxyHelper.php | 12 ++++++++---- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/Symfony/Component/Cache/Traits/Redis6Proxy.php b/src/Symfony/Component/Cache/Traits/Redis6Proxy.php index 24edb20bc37b3..0680404fc1eee 100644 --- a/src/Symfony/Component/Cache/Traits/Redis6Proxy.php +++ b/src/Symfony/Component/Cache/Traits/Redis6Proxy.php @@ -538,7 +538,7 @@ public function hVals($key): \Redis|array|false public function hscan($key, &$iterator, $pattern = null, $count = 0): \Redis|array|bool { - return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->hscan($key, $iterator, $pattern, $count, ...\array_slice(\func_get_args(), 4)); + return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->hscan($key, $iterator, ...\array_slice(\func_get_args(), 2)); } public function incr($key, $by = 1): \Redis|false|int @@ -888,7 +888,7 @@ public function save(): \Redis|bool public function scan(&$iterator, $pattern = null, $count = 0, $type = null): array|false { - return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->scan($iterator, $pattern, $count, $type, ...\array_slice(\func_get_args(), 4)); + return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->scan($iterator, ...\array_slice(\func_get_args(), 1)); } public function scard($key): \Redis|false|int @@ -998,7 +998,7 @@ public function srem($key, $value, ...$other_values): \Redis|false|int public function sscan($key, &$iterator, $pattern = null, $count = 0): array|false { - return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->sscan($key, $iterator, $pattern, $count, ...\array_slice(\func_get_args(), 4)); + return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->sscan($key, $iterator, ...\array_slice(\func_get_args(), 2)); } public function ssubscribe($channels, $cb): bool @@ -1278,7 +1278,7 @@ public function zinterstore($dst, $keys, $weights = null, $aggregate = null): \R public function zscan($key, &$iterator, $pattern = null, $count = 0): \Redis|array|false { - return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->zscan($key, $iterator, $pattern, $count, ...\array_slice(\func_get_args(), 4)); + return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->zscan($key, $iterator, ...\array_slice(\func_get_args(), 2)); } public function zunion($keys, $weights = null, $options = null): \Redis|array|false diff --git a/src/Symfony/Component/Cache/Traits/RedisCluster6Proxy.php b/src/Symfony/Component/Cache/Traits/RedisCluster6Proxy.php index 9b52a314e06ab..fafc4acf2df06 100644 --- a/src/Symfony/Component/Cache/Traits/RedisCluster6Proxy.php +++ b/src/Symfony/Component/Cache/Traits/RedisCluster6Proxy.php @@ -463,7 +463,7 @@ public function hmset($key, $key_values): \RedisCluster|bool public function hscan($key, &$iterator, $pattern = null, $count = 0): array|bool { - return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->hscan($key, $iterator, $pattern, $count, ...\array_slice(\func_get_args(), 4)); + return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->hscan($key, $iterator, ...\array_slice(\func_get_args(), 2)); } public function hrandfield($key, $options = null): \RedisCluster|array|string @@ -738,7 +738,7 @@ public function save($key_or_address): \RedisCluster|bool public function scan(&$iterator, $key_or_address, $pattern = null, $count = 0): array|bool { - return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->scan($iterator, $key_or_address, $pattern, $count, ...\array_slice(\func_get_args(), 4)); + return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->scan($iterator, ...\array_slice(\func_get_args(), 1)); } public function scard($key): \RedisCluster|false|int @@ -858,7 +858,7 @@ public function srem($key, $value, ...$other_values): \RedisCluster|false|int public function sscan($key, &$iterator, $pattern = null, $count = 0): array|false { - return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->sscan($key, $iterator, $pattern, $count, ...\array_slice(\func_get_args(), 4)); + return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->sscan($key, $iterator, ...\array_slice(\func_get_args(), 2)); } public function strlen($key): \RedisCluster|false|int @@ -1103,7 +1103,7 @@ public function zrevrank($key, $member): \RedisCluster|false|int public function zscan($key, &$iterator, $pattern = null, $count = 0): \RedisCluster|array|bool { - return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->zscan($key, $iterator, $pattern, $count, ...\array_slice(\func_get_args(), 4)); + return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->zscan($key, $iterator, ...\array_slice(\func_get_args(), 2)); } public function zscore($key, $member): \RedisCluster|false|float diff --git a/src/Symfony/Component/Cache/Traits/RelayProxy.php b/src/Symfony/Component/Cache/Traits/RelayProxy.php index 2f0e2c8460007..a9ad9c8403b65 100644 --- a/src/Symfony/Component/Cache/Traits/RelayProxy.php +++ b/src/Symfony/Component/Cache/Traits/RelayProxy.php @@ -984,22 +984,22 @@ public function clearBytes(): void public function scan(&$iterator, $match = null, $count = 0, $type = null): array|false { - return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->scan($iterator, $match, $count, $type, ...\array_slice(\func_get_args(), 4)); + return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->scan($iterator, ...\array_slice(\func_get_args(), 1)); } public function hscan($key, &$iterator, $match = null, $count = 0): array|false { - return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->hscan($key, $iterator, $match, $count, ...\array_slice(\func_get_args(), 4)); + return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->hscan($key, $iterator, ...\array_slice(\func_get_args(), 2)); } public function sscan($key, &$iterator, $match = null, $count = 0): array|false { - return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->sscan($key, $iterator, $match, $count, ...\array_slice(\func_get_args(), 4)); + return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->sscan($key, $iterator, ...\array_slice(\func_get_args(), 2)); } public function zscan($key, &$iterator, $match = null, $count = 0): array|false { - return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->zscan($key, $iterator, $match, $count, ...\array_slice(\func_get_args(), 4)); + return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->zscan($key, $iterator, ...\array_slice(\func_get_args(), 2)); } public function keys($pattern): \Relay\Relay|array|false diff --git a/src/Symfony/Component/Cache/composer.json b/src/Symfony/Component/Cache/composer.json index efec372c5ef50..82e2f49ce4b81 100644 --- a/src/Symfony/Component/Cache/composer.json +++ b/src/Symfony/Component/Cache/composer.json @@ -26,7 +26,7 @@ "psr/log": "^1.1|^2|^3", "symfony/cache-contracts": "^2.5|^3", "symfony/service-contracts": "^2.5|^3", - "symfony/var-exporter": "^6.2.10" + "symfony/var-exporter": "^6.3.6" }, "require-dev": { "cache/integration-tests": "dev-master", diff --git a/src/Symfony/Component/VarExporter/ProxyHelper.php b/src/Symfony/Component/VarExporter/ProxyHelper.php index 2e150cb5cedd9..155715de662c9 100644 --- a/src/Symfony/Component/VarExporter/ProxyHelper.php +++ b/src/Symfony/Component/VarExporter/ProxyHelper.php @@ -215,7 +215,7 @@ class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class); public static function exportSignature(\ReflectionFunctionAbstract $function, bool $withParameterTypes = true, string &$args = null): string { - $hasByRef = false; + $byRefIndex = 0; $args = ''; $param = null; $parameters = []; @@ -225,16 +225,20 @@ public static function exportSignature(\ReflectionFunctionAbstract $function, bo .($param->isPassedByReference() ? '&' : '') .($param->isVariadic() ? '...' : '').'$'.$param->name .($param->isOptional() && !$param->isVariadic() ? ' = '.self::exportDefault($param) : ''); - $hasByRef = $hasByRef || $param->isPassedByReference(); + if ($param->isPassedByReference()) { + $byRefIndex = 1 + $param->getPosition(); + } $args .= ($param->isVariadic() ? '...$' : '$').$param->name.', '; } - if (!$param || !$hasByRef) { + if (!$param || !$byRefIndex) { $args = '...\func_get_args()'; } elseif ($param->isVariadic()) { $args = substr($args, 0, -2); } else { - $args .= sprintf('...\array_slice(\func_get_args(), %d)', \count($parameters)); + $args = explode(', ', $args, 1 + $byRefIndex); + $args[$byRefIndex] = sprintf('...\array_slice(\func_get_args(), %d)', $byRefIndex); + $args = implode(', ', $args); } $signature = 'function '.($function->returnsReference() ? '&' : '')