Skip to content

Commit fc97603

Browse files
committed
Merge branch '7.0' into 7.1
* 7.0: synchronize Redis proxy traits for different versions [Serializer] Fixed BackedEnumNormalizer priority for translatable enum [Config] Fix `YamlReferenceDumper` handling of array examples [Yaml] prefix examples with #
2 parents e70dcb1 + 07d63d3 commit fc97603

File tree

12 files changed

+171
-61
lines changed

12 files changed

+171
-61
lines changed

src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,6 @@
212212
])
213213

214214
->set('serializer.normalizer.backed_enum', BackedEnumNormalizer::class)
215-
->tag('serializer.normalizer', ['priority' => -915])
215+
->tag('serializer.normalizer', ['priority' => -880])
216216
;
217217
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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\Bundle\FrameworkBundle\Tests\Fixtures;
13+
14+
use Symfony\Contracts\Translation\TranslatableInterface;
15+
use Symfony\Contracts\Translation\TranslatorInterface;
16+
17+
enum TranslatableBackedEnum: string implements TranslatableInterface
18+
{
19+
case Get = 'GET';
20+
21+
public function trans(TranslatorInterface $translator, ?string $locale = null): string
22+
{
23+
return match ($this) {
24+
self::Get => 'custom_get_string',
25+
};
26+
}
27+
}

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SerializerTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
1313

14+
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\TranslatableBackedEnum;
15+
1416
/**
1517
* @author Kévin Dunglas <[email protected]>
1618
*/
@@ -67,6 +69,15 @@ public static function provideNormalizersAndEncodersWithDefaultContextOption():
6769
['serializer.encoder.csv.alias'],
6870
];
6971
}
72+
73+
public function testSerializeTranslatableBackedEnum()
74+
{
75+
static::bootKernel(['test_case' => 'Serializer']);
76+
77+
$serializer = static::getContainer()->get('serializer.alias');
78+
79+
$this->assertEquals('GET', $serializer->serialize(TranslatableBackedEnum::Get, 'yaml'));
80+
}
7081
}
7182

7283
class Foo

src/Symfony/Component/Cache/Tests/Traits/RedisProxiesTest.php

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,32 +85,31 @@ public function testRelayProxy()
8585
*/
8686
public function testRedis6Proxy($class, $stub)
8787
{
88-
$stub = file_get_contents("https://raw.githubusercontent.com/phpredis/phpredis/develop/{$stub}.stub.php");
88+
if (version_compare(phpversion('redis'), '6.0.2', '>')) {
89+
$stub = file_get_contents("https://raw.githubusercontent.com/phpredis/phpredis/develop/{$stub}.stub.php");
90+
} else {
91+
$stub = file_get_contents("https://raw.githubusercontent.com/phpredis/phpredis/6.0.2/{$stub}.stub.php");
92+
}
93+
8994
$stub = preg_replace('/^class /m', 'return; \0', $stub);
9095
$stub = preg_replace('/^return; class ([a-zA-Z]++)/m', 'interface \1StubInterface', $stub, 1);
9196
$stub = preg_replace('/^ public const .*/m', '', $stub);
9297
eval(substr($stub, 5));
93-
$r = new \ReflectionClass($class.'StubInterface');
9498

95-
$proxy = file_get_contents(\dirname(__DIR__, 2)."/Traits/{$class}6Proxy.php");
96-
$proxy = substr($proxy, 0, 4 + strpos($proxy, '[];'));
99+
$this->assertEquals(self::dumpMethods(new \ReflectionClass($class.'StubInterface')), self::dumpMethods(new \ReflectionClass(sprintf('Symfony\Component\Cache\Traits\%s6Proxy', $class))));
100+
}
101+
102+
private static function dumpMethods(\ReflectionClass $class): string
103+
{
97104
$methods = [];
98105

99-
foreach ($r->getMethods() as $method) {
106+
foreach ($class->getMethods() as $method) {
100107
if ('reset' === $method->name || method_exists(LazyProxyTrait::class, $method->name)) {
101108
continue;
102109
}
110+
103111
$return = $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
104112
$signature = ProxyHelper::exportSignature($method, false, $args);
105-
106-
if ('Redis' === $class && 'mget' === $method->name) {
107-
$signature = str_replace(': \Redis|array|false', ': \Redis|array', $signature);
108-
}
109-
110-
if ('RedisCluster' === $class && 'publish' === $method->name) {
111-
$signature = str_replace(': \RedisCluster|bool|int', ': \RedisCluster|bool', $signature);
112-
}
113-
114113
$methods[] = "\n ".str_replace('timeout = 0.0', 'timeout = 0', $signature)."\n".<<<EOPHP
115114
{
116115
{$return}(\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}({$args});
@@ -119,9 +118,8 @@ public function testRedis6Proxy($class, $stub)
119118
EOPHP;
120119
}
121120

122-
uksort($methods, 'strnatcmp');
123-
$proxy .= implode('', $methods)."}\n";
121+
usort($methods, 'strnatcmp');
124122

125-
$this->assertStringEqualsFile(\dirname(__DIR__, 2)."/Traits/{$class}6Proxy.php", $proxy);
123+
return implode("\n", $methods);
126124
}
127125
}

src/Symfony/Component/Cache/Traits/Redis6Proxy.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Redis6Proxy extends \Redis implements ResetInterface, LazyObjectInterface
2828
use LazyProxyTrait {
2929
resetLazyObject as reset;
3030
}
31+
use Redis6ProxyTrait;
3132

3233
private const LAZY_OBJECT_PROPERTY_SCOPES = [];
3334

@@ -96,11 +97,6 @@ public function bgrewriteaof(): \Redis|bool
9697
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->bgrewriteaof(...\func_get_args());
9798
}
9899

99-
public function waitaof($numlocal, $numreplicas, $timeout): \Redis|array|false
100-
{
101-
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->waitaof(...\func_get_args());
102-
}
103-
104100
public function bitcount($key, $start = 0, $end = -1, $bybit = false): \Redis|false|int
105101
{
106102
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->bitcount(...\func_get_args());
@@ -231,11 +227,6 @@ public function discard(): \Redis|bool
231227
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->discard(...\func_get_args());
232228
}
233229

234-
public function dump($key): \Redis|string
235-
{
236-
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->dump(...\func_get_args());
237-
}
238-
239230
public function echo($str): \Redis|false|string
240231
{
241232
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->echo(...\func_get_args());
@@ -656,11 +647,6 @@ public function ltrim($key, $start, $end): \Redis|bool
656647
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->ltrim(...\func_get_args());
657648
}
658649

659-
public function mget($keys): \Redis|array
660-
{
661-
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->mget(...\func_get_args());
662-
}
663-
664650
public function migrate($host, $port, $key, $dstdb, $timeout, $copy = false, $replace = false, #[\SensitiveParameter] $credentials = null): \Redis|bool
665651
{
666652
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->migrate(...\func_get_args());
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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\Traits;
13+
14+
if (version_compare(phpversion('redis'), '6.0.2', '>')) {
15+
/**
16+
* @internal
17+
*/
18+
trait Redis6ProxyTrait
19+
{
20+
public function dump($key): \Redis|false|string
21+
{
22+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->dump(...\func_get_args());
23+
}
24+
25+
public function mget($keys): \Redis|array|false
26+
{
27+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->mget(...\func_get_args());
28+
}
29+
30+
public function waitaof($numlocal, $numreplicas, $timeout): \Redis|array|false
31+
{
32+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->waitaof(...\func_get_args());
33+
}
34+
}
35+
} else {
36+
/**
37+
* @internal
38+
*/
39+
trait Redis6ProxyTrait
40+
{
41+
public function dump($key): \Redis|string
42+
{
43+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->dump(...\func_get_args());
44+
}
45+
46+
public function mget($keys): \Redis|array
47+
{
48+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->mget(...\func_get_args());
49+
}
50+
}
51+
}

src/Symfony/Component/Cache/Traits/RedisCluster6Proxy.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class RedisCluster6Proxy extends \RedisCluster implements ResetInterface, LazyOb
2828
use LazyProxyTrait {
2929
resetLazyObject as reset;
3030
}
31+
use RedisCluster6ProxyTrait;
3132

3233
private const LAZY_OBJECT_PROPERTY_SCOPES = [];
3334

@@ -96,11 +97,6 @@ public function bgrewriteaof($key_or_address): \RedisCluster|bool
9697
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->bgrewriteaof(...\func_get_args());
9798
}
9899

99-
public function waitaof($key_or_address, $numlocal, $numreplicas, $timeout): \RedisCluster|array|false
100-
{
101-
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->waitaof(...\func_get_args());
102-
}
103-
104100
public function bgsave($key_or_address): \RedisCluster|bool
105101
{
106102
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->bgsave(...\func_get_args());
@@ -661,11 +657,6 @@ public function pttl($key): \RedisCluster|false|int
661657
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->pttl(...\func_get_args());
662658
}
663659

664-
public function publish($channel, $message): \RedisCluster|bool
665-
{
666-
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->publish(...\func_get_args());
667-
}
668-
669660
public function pubsub($key_or_address, ...$values): mixed
670661
{
671662
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->pubsub(...\func_get_args());
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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\Traits;
13+
14+
if (version_compare(phpversion('redis'), '6.0.2', '>')) {
15+
/**
16+
* @internal
17+
*/
18+
trait RedisCluster6ProxyTrait
19+
{
20+
public function publish($channel, $message): \RedisCluster|bool|int
21+
{
22+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->publish(...\func_get_args());
23+
}
24+
25+
public function waitaof($key_or_address, $numlocal, $numreplicas, $timeout): \RedisCluster|array|false
26+
{
27+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->waitaof(...\func_get_args());
28+
}
29+
}
30+
} else {
31+
/**
32+
* @internal
33+
*/
34+
trait RedisCluster6ProxyTrait
35+
{
36+
public function publish($channel, $message): \RedisCluster|bool
37+
{
38+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->publish(...\func_get_args());
39+
}
40+
}
41+
}

src/Symfony/Component/Config/Definition/Dumper/YamlReferenceDumper.php

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Symfony\Component\Config\Definition\NodeInterface;
1919
use Symfony\Component\Config\Definition\PrototypedArrayNode;
2020
use Symfony\Component\Config\Definition\ScalarNode;
21-
use Symfony\Component\Config\Definition\VariableNode;
2221
use Symfony\Component\Yaml\Inline;
2322

2423
/**
@@ -90,19 +89,12 @@ private function writeNode(NodeInterface $node, ?NodeInterface $parentNode = nul
9089
$children = $this->getPrototypeChildren($node);
9190
}
9291

93-
if (!$children) {
94-
if ($node->hasDefaultValue() && \count($defaultArray = $node->getDefaultValue())) {
95-
$default = '';
96-
} elseif (!\is_array($example)) {
97-
$default = '[]';
98-
}
92+
if (!$children && !($node->hasDefaultValue() && \count($defaultArray = $node->getDefaultValue()))) {
93+
$default = '[]';
9994
}
10095
} elseif ($node instanceof EnumNode) {
10196
$comments[] = 'One of '.$node->getPermissibleValues('; ');
10297
$default = $node->hasDefaultValue() ? Inline::dump($node->getDefaultValue()) : '~';
103-
} elseif (VariableNode::class === $node::class && \is_array($example)) {
104-
// If there is an array example, we are sure we dont need to print a default value
105-
$default = '';
10698
} else {
10799
$default = '~';
108100

@@ -170,7 +162,7 @@ private function writeNode(NodeInterface $node, ?NodeInterface $parentNode = nul
170162

171163
$this->writeLine('# '.$message.':', $depth * 4 + 4);
172164

173-
$this->writeArray(array_map(Inline::dump(...), $example), $depth + 1);
165+
$this->writeArray(array_map(Inline::dump(...), $example), $depth + 1, true);
174166
}
175167

176168
if ($children) {
@@ -191,7 +183,7 @@ private function writeLine(string $text, int $indent = 0): void
191183
$this->reference .= sprintf($format, $text)."\n";
192184
}
193185

194-
private function writeArray(array $array, int $depth): void
186+
private function writeArray(array $array, int $depth, bool $asComment = false): void
195187
{
196188
$isIndexed = array_is_list($array);
197189

@@ -201,15 +193,18 @@ private function writeArray(array $array, int $depth): void
201193
} else {
202194
$val = $value;
203195
}
196+
$prefix = $asComment ? '# ' : '';
197+
198+
$prefix = $asComment ? '# ' : '';
204199

205200
if ($isIndexed) {
206-
$this->writeLine('- '.$val, $depth * 4);
201+
$this->writeLine($prefix.'- '.$val, $depth * 4);
207202
} else {
208-
$this->writeLine(sprintf('%-20s %s', $key.':', $val), $depth * 4);
203+
$this->writeLine(sprintf('%s%-20s %s', $prefix, $key.':', $val), $depth * 4);
209204
}
210205

211206
if (\is_array($value)) {
212-
$this->writeArray($value, $depth + 1);
207+
$this->writeArray($value, $depth + 1, $asComment);
213208
}
214209
}
215210
}

src/Symfony/Component/Config/Tests/Definition/Dumper/XmlReferenceDumperTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ enum=""
109109
110110
</pipou>
111111
112+
<array-with-array-example-and-no-default-value />
113+
112114
</config>
113115

114116
EOL

0 commit comments

Comments
 (0)