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

Skip to content

[Cache] fix compatibility with Redis Relay 0.8.1 #57723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/Symfony/Component/Cache/Tests/Traits/RedisProxiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Relay\Relay;
use Symfony\Component\Cache\Traits\RelayProxy;
use Symfony\Component\VarExporter\LazyProxyTrait;
use Symfony\Component\VarExporter\ProxyHelper;

Expand Down Expand Up @@ -62,14 +63,30 @@ public function testRelayProxy()
{
$proxy = file_get_contents(\dirname(__DIR__, 2).'/Traits/RelayProxy.php');
$proxy = substr($proxy, 0, 4 + strpos($proxy, '[];'));
$expectedProxy = $proxy;
$methods = [];
$expectedMethods = [];

foreach ((new \ReflectionClass(RelayProxy::class))->getMethods() as $method) {
if ('reset' === $method->name || method_exists(LazyProxyTrait::class, $method->name) || $method->isStatic()) {
continue;
}

$return = $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
$expectedMethods[$method->name] = "\n ".ProxyHelper::exportSignature($method, false, $args)."\n".<<<EOPHP
{
{$return}(\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}({$args});
}

EOPHP;
}

foreach ((new \ReflectionClass(Relay::class))->getMethods() as $method) {
if ('reset' === $method->name || method_exists(LazyProxyTrait::class, $method->name) || $method->isStatic()) {
continue;
}
$return = $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
$methods[] = "\n ".ProxyHelper::exportSignature($method, false, $args)."\n".<<<EOPHP
$methods[$method->name] = "\n ".ProxyHelper::exportSignature($method, false, $args)."\n".<<<EOPHP
{
{$return}(\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}({$args});
}
Expand All @@ -80,6 +97,9 @@ public function testRelayProxy()
uksort($methods, 'strnatcmp');
$proxy .= implode('', $methods)."}\n";

$this->assertStringEqualsFile(\dirname(__DIR__, 2).'/Traits/RelayProxy.php', $proxy);
uksort($expectedMethods, 'strnatcmp');
$expectedProxy .= implode('', $expectedMethods)."}\n";

$this->assertEquals($expectedProxy, $proxy);
}
}
6 changes: 1 addition & 5 deletions src/Symfony/Component/Cache/Traits/RelayProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class RelayProxy extends \Relay\Relay implements ResetInterface, LazyObjectInter
use LazyProxyTrait {
resetLazyObject as reset;
}
use RelayProxyTrait;

private const LAZY_OBJECT_PROPERTY_SCOPES = [];

Expand Down Expand Up @@ -291,11 +292,6 @@ public function migrate($host, $port, $key, $dstdb, $timeout, $copy = false, $re
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->migrate(...\func_get_args());
}

public function copy($src, $dst, $options = null): \Relay\Relay|false|int
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->copy(...\func_get_args());
}

public function echo($arg): \Relay\Relay|bool|string
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->echo(...\func_get_args());
Expand Down
156 changes: 156 additions & 0 deletions src/Symfony/Component/Cache/Traits/RelayProxyTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Cache\Traits;

if (version_compare(phpversion('relay'), '0.8.1', '>=')) {
/**
* @internal
*/
trait RelayProxyTrait
{
public function copy($src, $dst, $options = null): \Relay\Relay|bool
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->copy(...\func_get_args());
}

public function jsonArrAppend($key, $value_or_array, $path = null): \Relay\Relay|array|false
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonArrAppend(...\func_get_args());
}

public function jsonArrIndex($key, $path, $value, $start = 0, $stop = -1): \Relay\Relay|array|false
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonArrIndex(...\func_get_args());
}

public function jsonArrInsert($key, $path, $index, $value, ...$other_values): \Relay\Relay|array|false
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonArrInsert(...\func_get_args());
}

public function jsonArrLen($key, $path = null): \Relay\Relay|array|false
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonArrLen(...\func_get_args());
}

public function jsonArrPop($key, $path = null, $index = -1): \Relay\Relay|array|false
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonArrPop(...\func_get_args());
}

public function jsonArrTrim($key, $path, $start, $stop): \Relay\Relay|array|false
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonArrTrim(...\func_get_args());
}

public function jsonClear($key, $path = null): \Relay\Relay|false|int
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonClear(...\func_get_args());
}

public function jsonDebug($command, $key, $path = null): \Relay\Relay|false|int
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonDebug(...\func_get_args());
}

public function jsonDel($key, $path = null): \Relay\Relay|false|int
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonDel(...\func_get_args());
}

public function jsonForget($key, $path = null): \Relay\Relay|false|int
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonForget(...\func_get_args());
}

public function jsonGet($key, $options = [], ...$paths): mixed
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonGet(...\func_get_args());
}

public function jsonMerge($key, $path, $value): \Relay\Relay|bool
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonMerge(...\func_get_args());
}

public function jsonMget($key_or_array, $path): \Relay\Relay|array|false
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonMget(...\func_get_args());
}

public function jsonMset($key, $path, $value, ...$other_triples): \Relay\Relay|bool
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonMset(...\func_get_args());
}

public function jsonNumIncrBy($key, $path, $value): \Relay\Relay|array|false
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonNumIncrBy(...\func_get_args());
}

public function jsonNumMultBy($key, $path, $value): \Relay\Relay|array|false
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonNumMultBy(...\func_get_args());
}

public function jsonObjKeys($key, $path = null): \Relay\Relay|array|false
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonObjKeys(...\func_get_args());
}

public function jsonObjLen($key, $path = null): \Relay\Relay|array|false
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonObjLen(...\func_get_args());
}

public function jsonResp($key, $path = null): \Relay\Relay|array|false|int|string
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonResp(...\func_get_args());
}

public function jsonSet($key, $path, $value, $condition = null): \Relay\Relay|bool
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonSet(...\func_get_args());
}

public function jsonStrAppend($key, $value, $path = null): \Relay\Relay|array|false
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonStrAppend(...\func_get_args());
}

public function jsonStrLen($key, $path = null): \Relay\Relay|array|false
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonStrLen(...\func_get_args());
}

public function jsonToggle($key, $path): \Relay\Relay|array|false
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonToggle(...\func_get_args());
}

public function jsonType($key, $path = null): \Relay\Relay|array|false
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonType(...\func_get_args());
}
}
} else {
/**
* @internal
*/
trait RelayProxyTrait

Check failure on line 149 in src/Symfony/Component/Cache/Traits/RelayProxyTrait.php

View workflow job for this annotation

GitHub Actions / Psalm

DuplicateClass

src/Symfony/Component/Cache/Traits/RelayProxyTrait.php:149:11: DuplicateClass: Class Symfony\Component\Cache\Traits\RelayProxyTrait has already been defined in /home/runner/work/symfony/symfony/src/Symfony/Component/Cache/Traits/RelayProxyTrait.php (see https://psalm.dev/071)

Check failure on line 149 in src/Symfony/Component/Cache/Traits/RelayProxyTrait.php

View workflow job for this annotation

GitHub Actions / Psalm

DuplicateClass

src/Symfony/Component/Cache/Traits/RelayProxyTrait.php:149:11: DuplicateClass: Class Symfony\Component\Cache\Traits\RelayProxyTrait has already been defined in /home/runner/work/symfony/symfony/src/Symfony/Component/Cache/Traits/RelayProxyTrait.php (see https://psalm.dev/071)
{
public function copy($src, $dst, $options = null): \Relay\Relay|false|int
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->copy(...\func_get_args());
}
}
}
Loading