Skip to content

[Cache] make Redis*Proxy extend Redis* #47292

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
Sep 12, 2022
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
4 changes: 2 additions & 2 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ install:
- cd ext
- appveyor DownloadFile https://github.com/symfony/binary-utils/releases/download/v0.1/php_apcu-5.1.21-8.1-ts-vs16-x86.zip
- 7z x php_apcu-5.1.21-8.1-ts-vs16-x86.zip -y >nul
- appveyor DownloadFile https://github.com/symfony/binary-utils/releases/download/v0.1/php_redis-5.3.7rc1-8.1-ts-vs16-x86.zip
- 7z x php_redis-5.3.7rc1-8.1-ts-vs16-x86.zip -y >nul
- appveyor DownloadFile https://github.com/symfony/binary-utils/releases/download/v0.1/php_redis-5.3.7-8.1-ts-vs16-x86.zip
- 7z x php_redis-5.3.7-8.1-ts-vs16-x86.zip -y >nul
- cd ..
- copy /Y php.ini-development php.ini-min
- echo memory_limit=-1 >> php.ini-min
Expand Down
9 changes: 8 additions & 1 deletion .github/patch-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@
Symfony\Component\ErrorHandler\DebugClassLoader::enable();

foreach ($loader->getClassMap() as $class => $file) {
$file = realpath($file);

switch (true) {
case false !== strpos($file = realpath($file), '/vendor/'):
case false !== strpos($file, '/src/Symfony/Component/Cache/Traits/Redis'):
if (!str_ends_with($file, 'Proxy.php')) {
break;
}
// no break;
case false !== strpos($file, '/vendor/'):
case false !== strpos($file, '/src/Symfony/Bridge/PhpUnit/'):
case false !== strpos($file, '/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Validation/Article.php'):
case false !== strpos($file, '/src/Symfony/Component/Cache/Tests/Fixtures/DriverWrapper.php'):
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
coverage: "none"
extensions: "json,couchbase-3.2.2,memcached,mongodb-1.12.0,redis-5.3.4,rdkafka,xsl,ldap"
extensions: "json,couchbase-3.2.2,memcached,mongodb-1.12.0,redis,rdkafka,xsl,ldap"
ini-values: date.timezone=Europe/Paris,memory_limit=-1,default_socket_timeout=10,session.gc_probability=0,apc.enable_cli=1,zend.assertions=1
php-version: "${{ matrix.php }}"
tools: pecl
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
name: Tests

env:
extensions: amqp,apcu,igbinary,intl,mbstring,memcached,redis-5.3.4
extensions: amqp,apcu,igbinary,intl,mbstring,memcached,redis

strategy:
matrix:
Expand Down
5 changes: 5 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
->notPath('Symfony/Component/ErrorHandler/Tests/DebugClassLoaderTest.php')
// stop removing spaces on the end of the line in strings
->notPath('Symfony/Component/Messenger/Tests/Command/FailedMessagesShowCommandTest.php')
// auto-generated proxies
->notPath('Symfony/Component/Cache/Traits/Redis5Proxy.php')
->notPath('Symfony/Component/Cache/Traits/Redis6Proxy.php')
->notPath('Symfony/Component/Cache/Traits/RedisCluster5Proxy.php')
->notPath('Symfony/Component/Cache/Traits/RedisCluster6Proxy.php')
)
->setCacheFile('.php-cs-fixer.cache')
;
4 changes: 1 addition & 3 deletions src/Symfony/Component/Cache/Adapter/RedisAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@
namespace Symfony\Component\Cache\Adapter;

use Symfony\Component\Cache\Marshaller\MarshallerInterface;
use Symfony\Component\Cache\Traits\RedisClusterProxy;
use Symfony\Component\Cache\Traits\RedisProxy;
use Symfony\Component\Cache\Traits\RedisTrait;

class RedisAdapter extends AbstractAdapter
{
use RedisTrait;

public function __construct(\Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy|RedisClusterProxy $redis, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
public function __construct(\Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface $redis, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
{
$this->init($redis, $namespace, $defaultLifetime, $marshaller);
}
Expand Down
4 changes: 1 addition & 3 deletions src/Symfony/Component/Cache/Adapter/RedisTagAwareAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
use Symfony\Component\Cache\Marshaller\DeflateMarshaller;
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
use Symfony\Component\Cache\Marshaller\TagAwareMarshaller;
use Symfony\Component\Cache\Traits\RedisClusterProxy;
use Symfony\Component\Cache\Traits\RedisProxy;
use Symfony\Component\Cache\Traits\RedisTrait;

/**
Expand Down Expand Up @@ -61,7 +59,7 @@ class RedisTagAwareAdapter extends AbstractTagAwareAdapter
private string $redisEvictionPolicy;
private string $namespace;

public function __construct(\Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy|RedisClusterProxy $redis, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
public function __construct(\Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface $redis, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
{
if ($redis instanceof \Predis\ClientInterface && $redis->getConnection() instanceof ClusterInterface && !$redis->getConnection() instanceof PredisCluster) {
throw new InvalidArgumentException(sprintf('Unsupported Predis cluster connection: only "%s" is, "%s" given.', PredisCluster::class, get_debug_type($redis->getConnection())));
Expand Down
85 changes: 85 additions & 0 deletions src/Symfony/Component/Cache/Tests/RedisProxiesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

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

namespace Symfony\Component\Cache\Tests\Traits;

use PHPUnit\Framework\TestCase;
use Symfony\Component\VarExporter\LazyProxyTrait;
use Symfony\Component\VarExporter\ProxyHelper;

/**
* @requires extension redis
*/
class RedisProxiesTest extends TestCase
{
/**
* @testWith ["Redis"]
* ["RedisCluster"]
*/
public function testRedis5Proxy($class)
{
$proxy = file_get_contents(\dirname(__DIR__)."/Traits/{$class}5Proxy.php");
$proxy = substr($proxy, 0, 8 + strpos($proxy, "\n ];"));
$methods = [];

foreach ((new \ReflectionClass($class))->getMethods() as $method) {
if ('reset' === $method->name || method_exists(LazyProxyTrait::class, $method->name)) {
continue;
}
$return = $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
$methods[] = "\n ".ProxyHelper::exportSignature($method, false)."\n".<<<EOPHP
{
{$return}\$this->lazyObjectReal->{$method->name}(...\\func_get_args());
}

EOPHP;
}

uksort($methods, 'strnatcmp');
$proxy .= implode('', $methods)."}\n";

$this->assertStringEqualsFile(\dirname(__DIR__)."/Traits/{$class}5Proxy.php", $proxy);
}

/**
* @testWith ["Redis", "redis"]
* ["RedisCluster", "redis_cluster"]
*/
public function testRedis6Proxy($class, $stub)
{
$stub = file_get_contents("https://raw.githubusercontent.com/phpredis/phpredis/develop/{$stub}.stub.php");
$stub = preg_replace('/^class /m', 'return; \0', $stub);
$stub = preg_replace('/^return; class ([a-zA-Z]++)/m', 'interface \1StubInterface', $stub, 1);
eval(substr($stub, 5));

$proxy = file_get_contents(\dirname(__DIR__)."/Traits/{$class}6Proxy.php");
$proxy = substr($proxy, 0, 8 + strpos($proxy, "\n ];"));
$methods = [];

foreach ((new \ReflectionClass($class.'StubInterface'))->getMethods() as $method) {
if ('reset' === $method->name || method_exists(LazyProxyTrait::class, $method->name)) {
continue;
}
$return = $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
$methods[] = "\n ".ProxyHelper::exportSignature($method, false)."\n".<<<EOPHP
{
{$return}\$this->lazyObjectReal->{$method->name}(...\\func_get_args());
}

EOPHP;
}

uksort($methods, 'strnatcmp');
$proxy .= implode('', $methods)."}\n";

$this->assertStringEqualsFile(\dirname(__DIR__)."/Traits/{$class}6Proxy.php", $proxy);
}
}
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy