Skip to content

Commit f767f62

Browse files
Merge branch '4.4' into 5.4
* 4.4: [Cache] Fix connecting to Redis via a socket file [DependencyInjection][FrameworkBundle] Fix using PHP 8.1 enum as parameters [PropertyAccessor] Add missing TypeError catch [FrameworkBundle] Fix log channel of TagAwareAdapter [HttpClient] Fix Content-Length header when possible [DependencyInjection] Don't dump polyfilled classes in preload script
2 parents d296d1e + 46b8354 commit f767f62

23 files changed

+188
-16
lines changed

Console/Descriptor/Descriptor.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,20 @@ protected function formatValue($value): string
173173
*/
174174
protected function formatParameter($value): string
175175
{
176+
if ($value instanceof \UnitEnum) {
177+
return var_export($value, true);
178+
}
179+
180+
// Recursively search for enum values, so we can replace it
181+
// before json_encode (which will not display anything for \UnitEnum otherwise)
182+
if (\is_array($value)) {
183+
array_walk_recursive($value, static function (&$value) {
184+
if ($value instanceof \UnitEnum) {
185+
$value = var_export($value, true);
186+
}
187+
});
188+
}
189+
176190
if (\is_bool($value) || \is_array($value) || (null === $value)) {
177191
$jsonString = json_encode($value);
178192

Console/Descriptor/JsonDescriptor.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,14 @@ private function writeData(array $data, array $options)
184184
{
185185
$flags = $options['json_encoding'] ?? 0;
186186

187+
// Recursively search for enum values, so we can replace it
188+
// before json_encode (which will not display anything for \UnitEnum otherwise)
189+
array_walk_recursive($data, static function (&$value) {
190+
if ($value instanceof \UnitEnum) {
191+
$value = var_export($value, true);
192+
}
193+
});
194+
187195
$this->write(json_encode($data, $flags | \JSON_PRETTY_PRINT)."\n");
188196
}
189197

Console/Descriptor/TextDescriptor.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ protected function describeContainerDefinition(Definition $definition, array $op
348348
$argumentsInformation[] = sprintf('Service locator (%d element(s))', \count($argument->getValues()));
349349
} elseif ($argument instanceof Definition) {
350350
$argumentsInformation[] = 'Inlined Service';
351+
} elseif ($argument instanceof \UnitEnum) {
352+
$argumentsInformation[] = var_export($argument, true);
351353
} elseif ($argument instanceof AbstractArgument) {
352354
$argumentsInformation[] = sprintf('Abstract argument (%s)', $argument->getText());
353355
} else {

Console/Descriptor/XmlDescriptor.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,9 @@ private function getArgumentNodes(array $arguments, \DOMDocument $dom): array
419419
foreach ($this->getArgumentNodes($argument, $dom) as $childArgumentXML) {
420420
$argumentXML->appendChild($childArgumentXML);
421421
}
422+
} elseif ($argument instanceof \UnitEnum) {
423+
$argumentXML->setAttribute('type', 'constant');
424+
$argumentXML->appendChild(new \DOMText(var_export($argument, true)));
422425
} else {
423426
$argumentXML->appendChild(new \DOMText($argument));
424427
}

Controller/AbstractController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function setContainer(ContainerInterface $container): ?ContainerInterface
7575
/**
7676
* Gets a container parameter by its name.
7777
*
78-
* @return array|bool|float|int|string|null
78+
* @return array|bool|float|int|string|\UnitEnum|null
7979
*/
8080
protected function getParameter(string $name)
8181
{

DependencyInjection/FrameworkExtension.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2256,7 +2256,8 @@ private function registerCacheConfiguration(array $config, ContainerBuilder $con
22562256
if (method_exists(TagAwareAdapter::class, 'setLogger')) {
22572257
$container
22582258
->getDefinition($name)
2259-
->addMethodCall('setLogger', [new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)]);
2259+
->addMethodCall('setLogger', [new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)])
2260+
->addTag('monolog.logger', ['channel' => 'cache']);
22602261
}
22612262

22622263
$pool['name'] = $tagAwareId = $name;

Test/TestContainer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function getParameterBag(): ParameterBagInterface
6464
/**
6565
* {@inheritdoc}
6666
*
67-
* @return array|bool|float|int|string|null
67+
* @return array|bool|float|int|string|\UnitEnum|null
6868
*/
6969
public function getParameter(string $name)
7070
{

Tests/Console/Descriptor/AbstractDescriptorTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\FooUnitEnum;
1516
use Symfony\Component\Console\Input\ArrayInput;
1617
use Symfony\Component\Console\Output\BufferedOutput;
1718
use Symfony\Component\Console\Style\SymfonyStyle;
@@ -121,6 +122,10 @@ public function getDescribeContainerDefinitionWithArgumentsShownTestData()
121122
$definitionsWithArgs[str_replace('definition_', 'definition_arguments_', $key)] = $definition;
122123
}
123124

125+
if (\PHP_VERSION_ID >= 80100) {
126+
$definitionsWithArgs['definition_arguments_with_enum'] = (new Definition('definition_with_enum'))->setArgument(0, FooUnitEnum::FOO);
127+
}
128+
124129
return $this->getDescriptionTestData($definitionsWithArgs);
125130
}
126131

@@ -261,7 +266,7 @@ private function assertDescription($expectedDescription, $describedObject, array
261266
}
262267
}
263268

264-
private function getDescriptionTestData(array $objects)
269+
private function getDescriptionTestData(iterable $objects)
265270
{
266271
$data = [];
267272
foreach ($objects as $name => $object) {

Tests/Console/Descriptor/ObjectsProvider.php

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

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor;
1313

14+
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\FooUnitEnum;
15+
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Suit;
1416
use Symfony\Component\DependencyInjection\Alias;
1517
use Symfony\Component\DependencyInjection\Argument\AbstractArgument;
1618
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
@@ -62,14 +64,26 @@ public static function getRoutes()
6264

6365
public static function getContainerParameters()
6466
{
65-
return [
66-
'parameters_1' => new ParameterBag([
67-
'integer' => 12,
68-
'string' => 'Hello world!',
69-
'boolean' => true,
70-
'array' => [12, 'Hello world!', true],
71-
]),
72-
];
67+
yield 'parameters_1' => new ParameterBag([
68+
'integer' => 12,
69+
'string' => 'Hello world!',
70+
'boolean' => true,
71+
'array' => [12, 'Hello world!', true],
72+
]);
73+
74+
if (\PHP_VERSION_ID < 80100) {
75+
return;
76+
}
77+
78+
yield 'parameters_enums' => new ParameterBag([
79+
'unit_enum' => FooUnitEnum::BAR,
80+
'backed_enum' => Suit::Hearts,
81+
'array_of_enums' => Suit::cases(),
82+
'map' => [
83+
'mixed' => [Suit::Hearts, FooUnitEnum::BAR],
84+
'single' => FooUnitEnum::BAR,
85+
],
86+
]);
7387
}
7488

7589
public static function getContainerParameter()

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,6 +1645,7 @@ public function testCachePoolServices()
16451645
$this->assertEquals([
16461646
['setLogger', [new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)]],
16471647
], $tagAwareDefinition->getMethodCalls());
1648+
$this->assertSame([['channel' => 'cache']], $tagAwareDefinition->getTag('monolog.logger'));
16481649
}
16491650
}
16501651

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"class": "definition_with_enum",
3+
"public": false,
4+
"synthetic": false,
5+
"lazy": false,
6+
"shared": true,
7+
"abstract": false,
8+
"autowire": false,
9+
"autoconfigure": false,
10+
"arguments": [
11+
"Symfony\\Bundle\\FrameworkBundle\\Tests\\Fixtures\\FooUnitEnum::FOO"
12+
],
13+
"file": null,
14+
"tags": []
15+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
- Class: `definition_with_enum`
2+
- Public: no
3+
- Synthetic: no
4+
- Lazy: no
5+
- Shared: yes
6+
- Abstract: no
7+
- Autowired: no
8+
- Autoconfigured: no
9+
- Arguments: yes
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---------------- ----------------------------------------------------------------
2+
 Option   Value 
3+
---------------- ----------------------------------------------------------------
4+
Service ID -
5+
Class definition_with_enum
6+
Tags -
7+
Public no
8+
Synthetic no
9+
Lazy no
10+
Shared yes
11+
Abstract no
12+
Autowired no
13+
Autoconfigured no
14+
Arguments Symfony\Bundle\FrameworkBundle\Tests\Fixtures\FooUnitEnum::FOO
15+
---------------- ----------------------------------------------------------------
16+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<definition class="definition_with_enum" public="false" synthetic="false" lazy="false" shared="true" abstract="false" autowired="false" autoconfigured="false" file="">
3+
<argument type="constant">Symfony\Bundle\FrameworkBundle\Tests\Fixtures\FooUnitEnum::FOO</argument>
4+
</definition>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"array_of_enums": [
3+
"Symfony\\Bundle\\FrameworkBundle\\Tests\\Fixtures\\Suit::Hearts",
4+
"Symfony\\Bundle\\FrameworkBundle\\Tests\\Fixtures\\Suit::Diamonds",
5+
"Symfony\\Bundle\\FrameworkBundle\\Tests\\Fixtures\\Suit::Clubs",
6+
"Symfony\\Bundle\\FrameworkBundle\\Tests\\Fixtures\\Suit::Spades"
7+
],
8+
"backed_enum": "Symfony\\Bundle\\FrameworkBundle\\Tests\\Fixtures\\Suit::Hearts",
9+
"map": {
10+
"mixed": [
11+
"Symfony\\Bundle\\FrameworkBundle\\Tests\\Fixtures\\Suit::Hearts",
12+
"Symfony\\Bundle\\FrameworkBundle\\Tests\\Fixtures\\FooUnitEnum::BAR"
13+
],
14+
"single": "Symfony\\Bundle\\FrameworkBundle\\Tests\\Fixtures\\FooUnitEnum::BAR"
15+
},
16+
"unit_enum": "Symfony\\Bundle\\FrameworkBundle\\Tests\\Fixtures\\FooUnitEnum::BAR"
17+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Container parameters
2+
====================
3+
4+
- `array_of_enums`: `["Symfony\\Bundle\\FrameworkBundle\\Tests\\Fixtures\\Suit::H...`
5+
- `backed_enum`: `Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Suit::Hearts`
6+
- `map`: `{"mixed":["Symfony\\Bundle\\FrameworkBundle\\Tests\\Fixtures...`
7+
- `unit_enum`: `Symfony\Bundle\FrameworkBundle\Tests\Fixtures\FooUnitEnum::BAR`
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Symfony Container Parameters
2+
============================
3+
4+
---------------- -----------------------------------------------------------------
5+
 Parameter   Value 
6+
---------------- -----------------------------------------------------------------
7+
array_of_enums ["Symfony\\Bundle\\FrameworkBundle\\Tests\\Fixtures\\Suit::H...
8+
backed_enum Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Suit::Hearts
9+
map {"mixed":["Symfony\\Bundle\\FrameworkBundle\\Tests\\Fixtures...
10+
unit_enum Symfony\Bundle\FrameworkBundle\Tests\Fixtures\FooUnitEnum::BAR
11+
---------------- -----------------------------------------------------------------
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<parameters>
3+
<parameter key="array_of_enums">["Symfony\\Bundle\\FrameworkBundle\\Tests\\Fixtures\\Suit::H...</parameter>
4+
<parameter key="backed_enum">Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Suit::Hearts</parameter>
5+
<parameter key="map">{"mixed":["Symfony\\Bundle\\FrameworkBundle\\Tests\\Fixtures...</parameter>
6+
<parameter key="unit_enum">Symfony\Bundle\FrameworkBundle\Tests\Fixtures\FooUnitEnum::BAR</parameter>
7+
</parameters>

Tests/Fixtures/FooUnitEnum.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
enum FooUnitEnum
15+
{
16+
case BAR;
17+
case FOO;
18+
}

Tests/Fixtures/Suit.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
enum Suit: string
15+
{
16+
case Hearts = 'H';
17+
case Diamonds = 'D';
18+
case Clubs = 'C';
19+
case Spades = 'S';
20+
}

Tests/Functional/CachePoolsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ protected static function createKernel(array $options = []): KernelInterface
121121
private function skipIfRedisUnavailable()
122122
{
123123
try {
124-
(new \Redis())->connect(getenv('REDIS_HOST'));
124+
(new \Redis())->connect(...explode(':', getenv('REDIS_HOST')));
125125
} catch (\Exception $e) {
126126
self::markTestSkipped($e->getMessage());
127127
}

Tests/Functional/app/CachePools/redis_custom_config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ services:
88
cache.test_redis_connection:
99
public: false
1010
class: Redis
11-
calls:
12-
- [connect, ['%env(REDIS_HOST)%']]
11+
factory: ['Symfony\Component\Cache\Adapter\RedisAdapter', 'createConnection']
12+
arguments: ['redis://%env(REDIS_HOST)%']
1313

1414
cache.app:
1515
parent: cache.adapter.redis

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"ext-xml": "*",
2121
"symfony/cache": "^5.2|^6.0",
2222
"symfony/config": "^5.3|^6.0",
23-
"symfony/dependency-injection": "^5.3|^6.0",
23+
"symfony/dependency-injection": "^5.4.5|^6.0.5",
2424
"symfony/deprecation-contracts": "^2.1|^3",
2525
"symfony/event-dispatcher": "^5.1|^6.0",
2626
"symfony/error-handler": "^4.4.1|^5.0.1|^6.0",

0 commit comments

Comments
 (0)