Skip to content

Commit ee78099

Browse files
minor #47292 [Cache] make Redis*Proxy extend Redis* (nicolas-grekas)
This PR was merged into the 6.2 branch. Discussion ---------- [Cache] make `Redis*Proxy` extend `Redis*` | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | Fix #47267, #42428 | License | MIT | Doc PR | - `Redis*Proxy` did not extend native classes because we missed the code infrastructure to generate appropriate proxies. With #47236, we now have it. This PR adds generated proxies to the cache component to keep it lazy-able out of the box. Commits ------- cfb46ed [Cache] make `Redis*Proxy` extend `Redis*`
2 parents 0b32537 + cfb46ed commit ee78099

29 files changed

+4555
-191
lines changed

.appveyor.yml

Lines changed: 2 additions & 2 deletions
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

.github/patch-types.php

Lines changed: 8 additions & 1 deletion
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'):

.github/workflows/integration-tests.yml

Lines changed: 1 addition & 1 deletion
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

.github/workflows/unit-tests.yml

Lines changed: 1 addition & 1 deletion
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:

.php-cs-fixer.dist.php

Lines changed: 5 additions & 0 deletions
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
;

src/Symfony/Component/Cache/Adapter/RedisAdapter.php

Lines changed: 1 addition & 3 deletions
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
}

src/Symfony/Component/Cache/Adapter/RedisTagAwareAdapter.php

Lines changed: 1 addition & 3 deletions
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())));
Lines changed: 85 additions & 0 deletions
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 <fabien@symfony.com>
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)
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