Skip to content

Commit

Permalink
Merge branch '7.0' into 7.1
Browse files Browse the repository at this point in the history
* 7.0:
  [Cache] Fix test failure related to Redis6Proxy on appveyor
  [Messenger] Fix reading pending messages with Redis
  [Serializer] Revert #54488 to fix BC Break
  [Validator] reviewed Polish translation for unit 113
  [Validator] Missing translations for Croatian (hr)
  Add hint which version of Symfony not longer require proxy manager bridge
  review and fix hungarian validation message
  Update translation
  review uk translations v2
  [Validator] Update message translations for unit 113 (TLD)
  [Intl] Remove resources data from classmap generation
  • Loading branch information
nicolas-grekas committed Apr 17, 2024
2 parents 9ec8b7c + 8447814 commit df033a0
Show file tree
Hide file tree
Showing 72 changed files with 156 additions and 492 deletions.
63 changes: 11 additions & 52 deletions src/Symfony/Component/Cache/Tests/Traits/RedisProxiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@
class RedisProxiesTest extends TestCase
{
/**
* @requires extension redis < 6
* @requires extension redis
*
* @testWith ["Redis"]
* ["RedisCluster"]
*/
public function testRedis5Proxy($class)
public function testRedisProxy($class)
{
$proxy = file_get_contents(\dirname(__DIR__, 2)."/Traits/{$class}5Proxy.php");
$proxy = substr($proxy, 0, 4 + strpos($proxy, '[];'));
$version = version_compare(phpversion('redis'), '6', '>') ? '6' : '5';
$proxy = file_get_contents(\dirname(__DIR__, 2)."/Traits/{$class}{$version}Proxy.php");
$expected = substr($proxy, 0, 4 + strpos($proxy, '[];'));
$methods = [];

foreach ((new \ReflectionClass($class))->getMethods() as $method) {
Expand All @@ -44,9 +45,13 @@ public function testRedis5Proxy($class)
}

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

if (!str_contains($expected, '#[\SensitiveParameter] ')) {
$proxy = str_replace('#[\SensitiveParameter] ', '', $proxy);
}

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

/**
Expand Down Expand Up @@ -76,50 +81,4 @@ public function testRelayProxy()

$this->assertStringEqualsFile(\dirname(__DIR__, 2).'/Traits/RelayProxy.php', $proxy);
}

/**
* @requires extension openssl
*
* @testWith ["Redis", "redis"]
* ["RedisCluster", "redis_cluster"]
*/
public function testRedis6Proxy($class, $stub)
{
if (version_compare(phpversion('redis'), '6.0.2', '>')) {
$stub = file_get_contents("https://raw.githubusercontent.com/phpredis/phpredis/develop/{$stub}.stub.php");
} else {
$stub = file_get_contents("https://raw.githubusercontent.com/phpredis/phpredis/6.0.2/{$stub}.stub.php");
}

$stub = preg_replace('/^class /m', 'return; \0', $stub);
$stub = preg_replace('/^return; class ([a-zA-Z]++)/m', 'interface \1StubInterface', $stub, 1);
$stub = preg_replace('/^ public const .*/m', '', $stub);
eval(substr($stub, 5));

$this->assertEquals(self::dumpMethods(new \ReflectionClass($class.'StubInterface')), self::dumpMethods(new \ReflectionClass(sprintf('Symfony\Component\Cache\Traits\%s6Proxy', $class))));
}

private static function dumpMethods(\ReflectionClass $class): string
{
$methods = [];

foreach ($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 ';
$signature = ProxyHelper::exportSignature($method, false, $args);
$methods[] = "\n ".str_replace('timeout = 0.0', 'timeout = 0', $signature)."\n".<<<EOPHP
{
{$return}(\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}({$args});
}
EOPHP;
}

usort($methods, 'strnatcmp');

return implode("\n", $methods);
}
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Traits/Redis5Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function append($key, $value)
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->append(...\func_get_args());
}

public function auth($auth)
public function auth(#[\SensitiveParameter] $auth)
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->auth(...\func_get_args());
}
Expand Down
11 changes: 10 additions & 1 deletion src/Symfony/Component/Cache/Traits/Redis6Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class Redis6Proxy extends \Redis implements ResetInterface, LazyObjectInterface
use LazyProxyTrait {
resetLazyObject as reset;
}
use Redis6ProxyTrait;

private const LAZY_OBJECT_PROPERTY_SCOPES = [];

Expand Down Expand Up @@ -227,6 +226,11 @@ public function discard(): \Redis|bool
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->discard(...\func_get_args());
}

public function dump($key): \Redis|string
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->dump(...\func_get_args());
}

public function echo($str): \Redis|false|string
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->echo(...\func_get_args());
Expand Down Expand Up @@ -647,6 +651,11 @@ public function ltrim($key, $start, $end): \Redis|bool
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->ltrim(...\func_get_args());
}

public function mget($keys): \Redis|array
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->mget(...\func_get_args());
}

public function migrate($host, $port, $key, $dstdb, $timeout, $copy = false, $replace = false, #[\SensitiveParameter] $credentials = null): \Redis|bool
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->migrate(...\func_get_args());
Expand Down
51 changes: 0 additions & 51 deletions src/Symfony/Component/Cache/Traits/Redis6ProxyTrait.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Traits/RedisCluster5Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class RedisCluster5Proxy extends \RedisCluster implements ResetInterface, LazyOb

private const LAZY_OBJECT_PROPERTY_SCOPES = [];

public function __construct($name, $seeds = null, $timeout = null, $read_timeout = null, $persistent = null, $auth = null)
public function __construct($name, $seeds = null, $timeout = null, $read_timeout = null, $persistent = null, #[\SensitiveParameter] $auth = null)
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->__construct(...\func_get_args());
}
Expand Down
6 changes: 5 additions & 1 deletion src/Symfony/Component/Cache/Traits/RedisCluster6Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class RedisCluster6Proxy extends \RedisCluster implements ResetInterface, LazyOb
use LazyProxyTrait {
resetLazyObject as reset;
}
use RedisCluster6ProxyTrait;

private const LAZY_OBJECT_PROPERTY_SCOPES = [];

Expand Down Expand Up @@ -657,6 +656,11 @@ public function pttl($key): \RedisCluster|false|int
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->pttl(...\func_get_args());
}

public function publish($channel, $message): \RedisCluster|bool
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->publish(...\func_get_args());
}

public function pubsub($key_or_address, ...$values): mixed
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->pubsub(...\func_get_args());
Expand Down
41 changes: 0 additions & 41 deletions src/Symfony/Component/Cache/Traits/RedisCluster6ProxyTrait.php

This file was deleted.

3 changes: 2 additions & 1 deletion src/Symfony/Component/Intl/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"autoload": {
"psr-4": { "Symfony\\Component\\Intl\\": "" },
"exclude-from-classmap": [
"/Tests/"
"/Tests/",
"/Resources/data/"
]
},
"minimum-stability": "dev"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ private function claimOldPendingMessages(): void
try {
// This could soon be optimized with https://github.com/antirez/redis/issues/5212 or
// https://github.com/antirez/redis/issues/6256
$pendingMessages = $this->getRedis()->xpending($this->stream, $this->group, '-', '+', 1);
$pendingMessages = $this->getRedis()->xpending($this->stream, $this->group, '-', '+', 1) ?: [];
} catch (\RedisException|\Relay\Exception $e) {
throw new TransportException($e->getMessage(), 0, $e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool

$accessorOrMutator = preg_match('/^(get|is|has|set)(.+)$/i', $method->name, $matches);
if ($accessorOrMutator) {
$attributeName = $reflectionClass->hasProperty($method->name) ? $method->name : lcfirst($matches[2]);
$attributeName = lcfirst($matches[2]);

if (isset($attributesMetadata[$attributeName])) {
$attributeMetadata = $attributesMetadata[$attributeName];
Expand Down
16 changes: 4 additions & 12 deletions src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,17 @@ protected function extractAttributes(object $object, ?string $format = null, arr

if (str_starts_with($name, 'get') || str_starts_with($name, 'has') || str_starts_with($name, 'can')) {
// getters, hassers and canners
$attributeName = $name;
$attributeName = substr($name, 3);

if (!$reflClass->hasProperty($attributeName)) {
$attributeName = substr($attributeName, 3);

if (!$reflClass->hasProperty($attributeName)) {
$attributeName = lcfirst($attributeName);
}
$attributeName = lcfirst($attributeName);
}
} elseif (str_starts_with($name, 'is')) {
// issers
$attributeName = $name;
$attributeName = substr($name, 2);

if (!$reflClass->hasProperty($attributeName)) {
$attributeName = substr($attributeName, 2);

if (!$reflClass->hasProperty($attributeName)) {
$attributeName = lcfirst($attributeName);
}
$attributeName = lcfirst($attributeName);
}
}

Expand Down

This file was deleted.

0 comments on commit df033a0

Please sign in to comment.