Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ee63ef5

Browse files
minor #57326 [Cache] Don't use LazyProxyTrait in redis proxies (nicolas-grekas)
This PR was merged into the 7.2 branch. Discussion ---------- [Cache] Don't use LazyProxyTrait in redis proxies | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT Making things a bit simpler. Forwarding dynamic properties to the real instance is the only benefit of using LazyProxyTrait here, and this has no use cases. Commits ------- 7fc68c9 [Cache] Don't use LazyProxyTrait in redis proxies
2 parents 0e786b6 + 7fc68c9 commit ee63ef5

File tree

7 files changed

+1223
-1190
lines changed

7 files changed

+1223
-1190
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Relay\Relay;
16-
use Symfony\Component\VarExporter\LazyProxyTrait;
16+
use Symfony\Component\Cache\Traits\RedisProxyTrait;
1717
use Symfony\Component\VarExporter\ProxyHelper;
1818

1919
class RedisProxiesTest extends TestCase
@@ -28,17 +28,17 @@ public function testRedisProxy($class)
2828
{
2929
$version = version_compare(phpversion('redis'), '6', '>') ? '6' : '5';
3030
$proxy = file_get_contents(\dirname(__DIR__, 2)."/Traits/{$class}{$version}Proxy.php");
31-
$expected = substr($proxy, 0, 4 + strpos($proxy, '[];'));
31+
$expected = substr($proxy, 0, 2 + strpos($proxy, '}'));
3232
$methods = [];
3333

3434
foreach ((new \ReflectionClass($class))->getMethods() as $method) {
35-
if ('reset' === $method->name || method_exists(LazyProxyTrait::class, $method->name)) {
35+
if ('reset' === $method->name || method_exists(RedisProxyTrait::class, $method->name)) {
3636
continue;
3737
}
38-
$return = $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
38+
$return = '__construct' === $method->name || $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
3939
$methods[] = "\n ".ProxyHelper::exportSignature($method, false, $args)."\n".<<<EOPHP
4040
{
41-
{$return}(\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}({$args});
41+
{$return}\$this->initializeLazyObject()->{$method->name}({$args});
4242
}
4343
4444
EOPHP;
@@ -60,17 +60,17 @@ public function testRedisProxy($class)
6060
public function testRelayProxy()
6161
{
6262
$proxy = file_get_contents(\dirname(__DIR__, 2).'/Traits/RelayProxy.php');
63-
$proxy = substr($proxy, 0, 4 + strpos($proxy, '[];'));
63+
$proxy = substr($proxy, 0, 2 + strpos($proxy, '}'));
6464
$methods = [];
6565

6666
foreach ((new \ReflectionClass(Relay::class))->getMethods() as $method) {
67-
if ('reset' === $method->name || method_exists(LazyProxyTrait::class, $method->name) || $method->isStatic()) {
67+
if ('reset' === $method->name || method_exists(RedisProxyTrait::class, $method->name) || $method->isStatic()) {
6868
continue;
6969
}
70-
$return = $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
70+
$return = '__construct' === $method->name || $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
7171
$methods[] = "\n ".ProxyHelper::exportSignature($method, false, $args)."\n".<<<EOPHP
7272
{
73-
{$return}(\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}({$args});
73+
{$return}\$this->initializeLazyObject()->{$method->name}({$args});
7474
}
7575
7676
EOPHP;

0 commit comments

Comments
 (0)