Skip to content

Commit cfb46ed

Browse files
[Cache] make Redis*Proxy extend Redis*
1 parent 1198986 commit cfb46ed

29 files changed

+4555
-191
lines changed

Diff for: .appveyor.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ install:
1818
- cd ext
1919
- appveyor DownloadFile https://github.com/symfony/binary-utils/releases/download/v0.1/php_apcu-5.1.21-8.1-ts-vs16-x86.zip
2020
- 7z x php_apcu-5.1.21-8.1-ts-vs16-x86.zip -y >nul
21-
- appveyor DownloadFile https://github.com/symfony/binary-utils/releases/download/v0.1/php_redis-5.3.7rc1-8.1-ts-vs16-x86.zip
22-
- 7z x php_redis-5.3.7rc1-8.1-ts-vs16-x86.zip -y >nul
21+
- appveyor DownloadFile https://github.com/symfony/binary-utils/releases/download/v0.1/php_redis-5.3.7-8.1-ts-vs16-x86.zip
22+
- 7z x php_redis-5.3.7-8.1-ts-vs16-x86.zip -y >nul
2323
- cd ..
2424
- copy /Y php.ini-development php.ini-min
2525
- echo memory_limit=-1 >> php.ini-min

Diff for: .github/patch-types.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@
1212
Symfony\Component\ErrorHandler\DebugClassLoader::enable();
1313

1414
foreach ($loader->getClassMap() as $class => $file) {
15+
$file = realpath($file);
16+
1517
switch (true) {
16-
case false !== strpos($file = realpath($file), '/vendor/'):
18+
case false !== strpos($file, '/src/Symfony/Component/Cache/Traits/Redis'):
19+
if (!str_ends_with($file, 'Proxy.php')) {
20+
break;
21+
}
22+
// no break;
23+
case false !== strpos($file, '/vendor/'):
1724
case false !== strpos($file, '/src/Symfony/Bridge/PhpUnit/'):
1825
case false !== strpos($file, '/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Validation/Article.php'):
1926
case false !== strpos($file, '/src/Symfony/Component/Cache/Tests/Fixtures/DriverWrapper.php'):

Diff for: .github/workflows/integration-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ jobs:
134134
uses: shivammathur/setup-php@v2
135135
with:
136136
coverage: "none"
137-
extensions: "json,couchbase-3.2.2,memcached,mongodb-1.12.0,redis-5.3.4,rdkafka,xsl,ldap"
137+
extensions: "json,couchbase-3.2.2,memcached,mongodb-1.12.0,redis,rdkafka,xsl,ldap"
138138
ini-values: date.timezone=Europe/Paris,memory_limit=-1,default_socket_timeout=10,session.gc_probability=0,apc.enable_cli=1,zend.assertions=1
139139
php-version: "${{ matrix.php }}"
140140
tools: pecl

Diff for: .github/workflows/unit-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
name: Tests
2222

2323
env:
24-
extensions: amqp,apcu,igbinary,intl,mbstring,memcached,redis-5.3.4
24+
extensions: amqp,apcu,igbinary,intl,mbstring,memcached,redis
2525

2626
strategy:
2727
matrix:

Diff for: .php-cs-fixer.dist.php

+5
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@
6666
->notPath('Symfony/Component/ErrorHandler/Tests/DebugClassLoaderTest.php')
6767
// stop removing spaces on the end of the line in strings
6868
->notPath('Symfony/Component/Messenger/Tests/Command/FailedMessagesShowCommandTest.php')
69+
// auto-generated proxies
70+
->notPath('Symfony/Component/Cache/Traits/Redis5Proxy.php')
71+
->notPath('Symfony/Component/Cache/Traits/Redis6Proxy.php')
72+
->notPath('Symfony/Component/Cache/Traits/RedisCluster5Proxy.php')
73+
->notPath('Symfony/Component/Cache/Traits/RedisCluster6Proxy.php')
6974
)
7075
->setCacheFile('.php-cs-fixer.cache')
7176
;

Diff for: src/Symfony/Component/Cache/Adapter/RedisAdapter.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@
1212
namespace Symfony\Component\Cache\Adapter;
1313

1414
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
15-
use Symfony\Component\Cache\Traits\RedisClusterProxy;
16-
use Symfony\Component\Cache\Traits\RedisProxy;
1715
use Symfony\Component\Cache\Traits\RedisTrait;
1816

1917
class RedisAdapter extends AbstractAdapter
2018
{
2119
use RedisTrait;
2220

23-
public function __construct(\Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy|RedisClusterProxy $redis, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
21+
public function __construct(\Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface $redis, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
2422
{
2523
$this->init($redis, $namespace, $defaultLifetime, $marshaller);
2624
}

Diff for: src/Symfony/Component/Cache/Adapter/RedisTagAwareAdapter.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
use Symfony\Component\Cache\Marshaller\DeflateMarshaller;
2323
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
2424
use Symfony\Component\Cache\Marshaller\TagAwareMarshaller;
25-
use Symfony\Component\Cache\Traits\RedisClusterProxy;
26-
use Symfony\Component\Cache\Traits\RedisProxy;
2725
use Symfony\Component\Cache\Traits\RedisTrait;
2826

2927
/**
@@ -61,7 +59,7 @@ class RedisTagAwareAdapter extends AbstractTagAwareAdapter
6159
private string $redisEvictionPolicy;
6260
private string $namespace;
6361

64-
public function __construct(\Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy|RedisClusterProxy $redis, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
62+
public function __construct(\Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface $redis, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
6563
{
6664
if ($redis instanceof \Predis\ClientInterface && $redis->getConnection() instanceof ClusterInterface && !$redis->getConnection() instanceof PredisCluster) {
6765
throw new InvalidArgumentException(sprintf('Unsupported Predis cluster connection: only "%s" is, "%s" given.', PredisCluster::class, get_debug_type($redis->getConnection())));
+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Cache\Tests\Traits;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\VarExporter\LazyProxyTrait;
16+
use Symfony\Component\VarExporter\ProxyHelper;
17+
18+
/**
19+
* @requires extension redis
20+
*/
21+
class RedisProxiesTest extends TestCase
22+
{
23+
/**
24+
* @testWith ["Redis"]
25+
* ["RedisCluster"]
26+
*/
27+
public function testRedis5Proxy($class)
28+
{
29+
$proxy = file_get_contents(\dirname(__DIR__)."/Traits/{$class}5Proxy.php");
30+
$proxy = substr($proxy, 0, 8 + strpos($proxy, "\n ];"));
31+
$methods = [];
32+
33+
foreach ((new \ReflectionClass($class))->getMethods() as $method) {
34+
if ('reset' === $method->name || method_exists(LazyProxyTrait::class, $method->name)) {
35+
continue;
36+
}
37+
$return = $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
38+
$methods[] = "\n ".ProxyHelper::exportSignature($method, false)."\n".<<<EOPHP
39+
{
40+
{$return}\$this->lazyObjectReal->{$method->name}(...\\func_get_args());
41+
}
42+
43+
EOPHP;
44+
}
45+
46+
uksort($methods, 'strnatcmp');
47+
$proxy .= implode('', $methods)."}\n";
48+
49+
$this->assertStringEqualsFile(\dirname(__DIR__)."/Traits/{$class}5Proxy.php", $proxy);
50+
}
51+
52+
/**
53+
* @testWith ["Redis", "redis"]
54+
* ["RedisCluster", "redis_cluster"]
55+
*/
56+
public function testRedis6Proxy($class, $stub)
57+
{
58+
$stub = file_get_contents("https://raw.githubusercontent.com/phpredis/phpredis/develop/{$stub}.stub.php");
59+
$stub = preg_replace('/^class /m', 'return; \0', $stub);
60+
$stub = preg_replace('/^return; class ([a-zA-Z]++)/m', 'interface \1StubInterface', $stub, 1);
61+
eval(substr($stub, 5));
62+
63+
$proxy = file_get_contents(\dirname(__DIR__)."/Traits/{$class}6Proxy.php");
64+
$proxy = substr($proxy, 0, 8 + strpos($proxy, "\n ];"));
65+
$methods = [];
66+
67+
foreach ((new \ReflectionClass($class.'StubInterface'))->getMethods() as $method) {
68+
if ('reset' === $method->name || method_exists(LazyProxyTrait::class, $method->name)) {
69+
continue;
70+
}
71+
$return = $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
72+
$methods[] = "\n ".ProxyHelper::exportSignature($method, false)."\n".<<<EOPHP
73+
{
74+
{$return}\$this->lazyObjectReal->{$method->name}(...\\func_get_args());
75+
}
76+
77+
EOPHP;
78+
}
79+
80+
uksort($methods, 'strnatcmp');
81+
$proxy .= implode('', $methods)."}\n";
82+
83+
$this->assertStringEqualsFile(\dirname(__DIR__)."/Traits/{$class}6Proxy.php", $proxy);
84+
}
85+
}

0 commit comments

Comments
 (0)