Skip to content

Commit c0f8160

Browse files
Merge branch '6.0' into 6.1
* 6.0: [Semaphore] fix tests [HttpClient] fix destructing CurlResponse [Cache] Fix connecting to Redis via a socket file [DependencyInjection][FrameworkBundle] Fix using PHP 8.1 enum as parameters [PropertyAccessor] Add missing TypeError catch [HttpKernel] Fixed error count by log not displayed in WebProfilerBundle Added `kernel.event_listener` to the default list of behavior describing tags, fixing AsEventListener attribute not working on decorators. [HttpKernel] Fix FileLinkFormatter with empty xdebug.file_link_format [WebProfilerBundle] Fixes weird spacing in log message context/trace output [Notifier] fix Microsoft Teams webhook url [FrameworkBundle] Fix log channel of TagAwareAdapter [Postmark] ensure only a single tag can be used with Postmark [Mailer] allow Mailchimp to handle multiple TagHeader's [HttpClient] Fix Content-Length header when possible [Routing] AnnotationDirectoryLoader::load() may return null [DependencyInjection] Don't dump polyfilled classes in preload script
2 parents 972295c + a6a07c8 commit c0f8160

23 files changed

+190
-16
lines changed

Console/Descriptor/Descriptor.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,20 @@ protected function formatValue(mixed $value): string
158158

159159
protected function formatParameter(mixed $value): string
160160
{
161+
if ($value instanceof \UnitEnum) {
162+
return var_export($value, true);
163+
}
164+
165+
// Recursively search for enum values, so we can replace it
166+
// before json_encode (which will not display anything for \UnitEnum otherwise)
167+
if (\is_array($value)) {
168+
array_walk_recursive($value, static function (&$value) {
169+
if ($value instanceof \UnitEnum) {
170+
$value = var_export($value, true);
171+
}
172+
});
173+
}
174+
161175
if (\is_bool($value) || \is_array($value) || (null === $value)) {
162176
$jsonString = json_encode($value);
163177

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
@@ -71,7 +71,7 @@ public function setContainer(ContainerInterface $container): ?ContainerInterface
7171
/**
7272
* Gets a container parameter by its name.
7373
*/
74-
protected function getParameter(string $name): array|bool|float|int|string|null
74+
protected function getParameter(string $name): array|bool|string|int|float|\UnitEnum|null
7575
{
7676
if (!$this->container->has('parameter_bag')) {
7777
throw new ServiceNotFoundException('parameter_bag.', null, null, [], sprintf('The "%s::getParameter()" method is missing a parameter bag to work properly. Did you forget to register your controller as a service subscriber? This can be fixed either by using autoconfiguration or by manually wiring a "parameter_bag" in the service locator passed to the controller.', static::class));

DependencyInjection/FrameworkExtension.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ public function load(array $configs, ContainerBuilder $container)
633633
'container.service_locator',
634634
'container.service_subscriber',
635635
'kernel.event_subscriber',
636+
'kernel.event_listener',
636637
'kernel.locale_aware',
637638
'kernel.reset',
638639
]);
@@ -2160,7 +2161,8 @@ private function registerCacheConfiguration(array $config, ContainerBuilder $con
21602161
if (method_exists(TagAwareAdapter::class, 'setLogger')) {
21612162
$container
21622163
->getDefinition($name)
2163-
->addMethodCall('setLogger', [new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)]);
2164+
->addMethodCall('setLogger', [new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)])
2165+
->addTag('monolog.logger', ['channel' => 'cache']);
21642166
}
21652167

21662168
$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-
public function getParameter(string $name): array|bool|float|int|string|null
67+
public function getParameter(string $name): array|bool|string|int|float|\UnitEnum|null
6868
{
6969
return $this->getPublicContainer()->getParameter($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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,7 @@ public function testCachePoolServices()
15621562
$this->assertEquals([
15631563
['setLogger', [new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)]],
15641564
], $tagAwareDefinition->getMethodCalls());
1565+
$this->assertSame([['channel' => 'cache']], $tagAwareDefinition->getTag('monolog.logger'));
15651566
}
15661567
}
15671568

@@ -1858,6 +1859,7 @@ public function testRegisterParameterCollectingBehaviorDescribingTags()
18581859
'container.service_locator',
18591860
'container.service_subscriber',
18601861
'kernel.event_subscriber',
1862+
'kernel.event_listener',
18611863
'kernel.locale_aware',
18621864
'kernel.reset',
18631865
], $container->getParameter('container.behavior_describing_tags'));
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
@@ -21,7 +21,7 @@
2121
"ext-xml": "*",
2222
"symfony/cache": "^5.4|^6.0",
2323
"symfony/config": "^5.4|^6.0",
24-
"symfony/dependency-injection": "^5.4|^6.0",
24+
"symfony/dependency-injection": "^5.4.5|^6.0.5",
2525
"symfony/event-dispatcher": "^5.4|^6.0",
2626
"symfony/error-handler": "^5.4|^6.0",
2727
"symfony/http-foundation": "^5.4|^6.0",

0 commit comments

Comments
 (0)