8000 Merge branch '6.2' into 6.3 · symfony/symfony@5aa7633 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5aa7633

Browse files
Merge branch '6.2' into 6.3
* 6.2: [VarExporter] Fix forwarding references to proxied classes
2 parents eece9de + b3bfdf9 commit 5aa7633

File tree

9 files changed

+1181
-1183
lines changed

9 files changed

+1181
-1183
lines changed

src/Symfony/Component/Cache/Tests/Traits/RedisProxiesTest.php

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,8 @@ public function testRedis5Proxy($class)
3434
if ('reset' === $method->name || method_exists(LazyProxyTrait::class, $method->name)) {
3535
continue;
3636
}
37-
$args = [];
38-
foreach ($method->getParameters() as $param) {
39-
$args[] = ($param->isVariadic() ? '...' : '').'$'.$param->name;
40-
}
41-
$args = implode(', ', $args);
4237
$return = $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
43-
$methods[] = "\n ".ProxyHelper::exportSignature($method, false)."\n".<<<EOPHP
38+
$methods[] = "\n ".ProxyHelper::exportSignature($method, false, $args)."\n".<<<EOPHP
4439
{
4540
{$return}(\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}({$args});
4641
}
@@ -68,13 +63,8 @@ public function testRelayProxy()
6863
if ('reset' === $method->name || method_exists(LazyProxyTrait::class, $method->name) || $method->isStatic()) {
6964
continue;
7065
}
71-
$args = [];
72-
foreach ($method->getParameters() as $param) {
73-
$args[] = ($param->isVariadic() ? '...' : '').'$'.$param->name;
74-
}
75-
$args = implode(', ', $args);
7666
$return = $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
77-
$methods[] = "\n ".ProxyHelper::exportSignature($method, false)."\n".<<<EOPHP
67+
$methods[] = "\n ".ProxyHelper::exportSignature($method, false, $args)."\n".<<<EOPHP
7868
{
7969
{$return}(\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}({$args});
8070
}
@@ -112,13 +102,8 @@ public function testRedis6Proxy($class, $stub)
112102
if ('reset' === $method->name || method_exists(LazyProxyTrait::class, $method->name)) {
113103
continue;
114104
}
115-
$args = [];
116-
foreach ($method->getParameters() as $param) {
117-
$args[] = ($param->isVariadic() ? '...' : '').'$'.$param->name;
118-
}
119-
$args = implode(', ', $args);
120105
$return = $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
121-
$methods[] = "\n ".ProxyHelper::exportSignature($method, false)."\n".<<<EOPHP
106+
$methods[] = "\n ".ProxyHelper::exportSignature($method, false, $args)."\n".<<<EOPHP
122107
{
123108
{$return}(\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}({$args});
124109
}

src/Symfony/Component/Cache/Traits/Redis5Proxy.php

Lines changed: 239 additions & 239 deletions
Large diffs are not rendered by default.

src/Symfony/Component/Cache/Traits/Redis6Proxy.php

Lines changed: 253 additions & 253 deletions
Large diffs are not rendered by default.

src/Symfony/Component/Cache/Traits/RedisCluster5Proxy.php

Lines changed: 190 additions & 190 deletions
Large diffs are not rendered by default.

src/Symfony/Component/Cache/Traits/RedisCluster6Proxy.php

Lines changed: 223 additions & 223 deletions
Large diffs are not rendered by default.

src/Symfony/Component/Cache/Traits/RelayProxy.php

Lines changed: 247 additions & 247 deletions
Large diffs are not rendered by default.

src/Symfony/Component/Cache/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"psr/log": "^1.1|^2|^3",
2727
"symfony/cache-contracts": "^2.5|^3",
2828
"symfony/service-contracts": "^2.5|^3",
29-
"symfony/var-exporter": "^6.2.7"
29+
"symfony/var-exporter": "^6.2.10"
3030
},
3131
"require-dev": {
3232
"cache/integration-tests": "dev-master",

src/Symfony/Component/VarExporter/ProxyHelper.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,15 @@ public static function generateLazyProxy(?\ReflectionClass $class, array $interf
142142
continue;
143143
}
144144

145-
$signature = self::exportSignature($method);
146-
$parentCall = $method->isAbstract() ? "throw new \BadMethodCallException('Cannot forward abstract method \"{$method->class}::{$method->name}()\".')" : "parent::{$method->name}(...\\func_get_args())";
145+
$signature = self::exportSignature($method, true, $args);
146+
$parentCall = $method->isAbstract() ? "throw new \BadMethodCallException('Cannot forward abstract method \"{$method->class}::{$method->name}()\".')" : "parent::{$method->name}({$args})";
147147

148148
if ($method->isStatic()) {
149149
$body = " $parentCall;";
150150
} elseif (str_ends_with($signature, '): never') || str_ends_with($signature, '): void')) {
151151
$body = <<<EOPHP
152152
if (isset(\$this->lazyObjectState)) {
153-
(\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}(...\\func_get_args());
153+
(\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}({$args});
154154
} else {
155155
{$parentCall};
156156
}
@@ -172,7 +172,7 @@ public static function generateLazyProxy(?\ReflectionClass $class, array $interf
172172

173173
$body = <<<EOPHP
174174
if (isset(\$this->lazyObjectState)) {
175-
return (\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}(...\\func_get_args());
175+
return (\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}({$args});
176176
}
177177
178178
return {$parentCall};
@@ -213,15 +213,28 @@ class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class);
213213
EOPHP;
214214
}
215215

216-
public static function exportSignature(\ReflectionFunctionAbstract $function, bool $withParameterTypes = true): string
216+
public static function exportSignature(\ReflectionFunctionAbstract $function, bool $withParameterTypes = true, string &$args = null): string
217217
{
218+
$hasByRef = false;
219+
$args = '';
220+
$param = null;
218221
$parameters = [];
219222
foreach ($function->getParameters() as $param) {
220223
$parameters[] = ($param->getAttributes(\SensitiveParameter::class) ? '#[\SensitiveParameter] ' : '')
221224
.($withParameterTypes && $param->hasType() ? self::exportType($param).' ' : '')
222225
.($param->isPassedByReference() ? '&' : '')
223226
.($param->isVariadic() ? '...' : '').'$'.$param->name
224227
.($param->isOptional() && !$param->isVariadic() ? ' = '.self::exportDefault($param) : '');
228+
$hasByRef = $hasByRef || $param->isPassedByReference();
229+
$args .= ($param->isVariadic() ? '...$' : '$').$param->name.', ';
230+
}
231+
232+
if (!$param || !$hasByRef) {
233+
$args = '...\func_get_args()';
234+
} elseif ($param->isVariadic()) {
235+
$args = substr($args, 0, -2);
236+
} else {
237+
$args .= sprintf('...\array_slice(\func_get_args(), %d)', \count($parameters));
225238
}
226239

227240
$signature = 'function '.($function->returnsReference() ? '&' : '')

src/Symfony/Component/VarExporter/Tests/ProxyHelperTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ public function foo1(): ?\Symfony\Component\VarExporter\Tests\Bar
7777
return parent::foo1(...\func_get_args());
7878
}
7979
80-
public function foo4(\Symfony\Component\VarExporter\Tests\Bar|string $b): void
80+
public function foo4(\Symfony\Component\VarExporter\Tests\Bar|string $b, &$d): void
8181
{
8282
if (isset($this->lazyObjectState)) {
83-
($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->foo4(...\func_get_args());
83+
($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->foo4($b, $d, ...\array_slice(\func_get_args(), 2));
8484
} else {
85-
parent::foo4(...\func_get_args());
85+
parent::foo4($b, $d, ...\array_slice(\func_get_args(), 2));
8686
}
8787
}
8888
@@ -133,7 +133,7 @@ public function foo1(): ?\Symfony\Component\VarExporter\Tests\Bar
133133
return throw new \BadMethodCallException('Cannot forward abstract method "Symfony\Component\VarExporter\Tests\TestForProxyHelperInterface1::foo1()".');
134134
}
135135
136-
public function foo2(?\Symfony\Component\VarExporter\Tests\Bar $b): \Symfony\Component\VarExporter\Tests\TestForProxyHelperInterface2
136+
public function foo2(?\Symfony\Component\VarExporter\Tests\Bar $b, ...$d): \Symfony\Component\VarExporter\Tests\TestForProxyHelperInterface2
137137
{
138138
if (isset($this->lazyObjectState)) {
139139
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->foo2(...\func_get_args());
@@ -196,15 +196,15 @@ public function foo1(): ?Bar
196196
{
197197
}
198198

199-
public function foo2(?Bar $b): ?self
199+
public function foo2(?Bar $b, ...$d): ?self
200200
{
201201
}
202202

203203
public function &foo3(Bar &$b, string &...$c)
204204
{
205205
}
206206

207-
public function foo4(Bar|string $b): void
207+
public function foo4(Bar|string $b, &$d): void
208208
{
209209
}
210210

@@ -234,7 +234,7 @@ public function foo1(): ?Bar;
234234

235235
interface TestForProxyHelperInterface2
236236
{
237-
public function foo2(?Bar $b): self;
237+
public function foo2(?Bar $b, ...$d): self;
238238

239239
public static function foo3(): string;
240240
}

0 commit comments

Comments
 (0)
0