Skip to content

Commit 490aa60

Browse files
Merge branch '5.4' into 6.0
* 5.4: [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. [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 [DependencyInjection] Don't dump polyfilled classes in preload script
2 parents 9a705fa + f767f62 commit 490aa60

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
@@ -624,6 +624,7 @@ public function load(array $configs, ContainerBuilder $container)
624624
'container.service_locator',
625625
'container.service_subscriber',
626626
'kernel.event_subscriber',
627+
'kernel.event_listener',
627628
'kernel.locale_aware',
628629
'kernel.reset',
629630
]);
@@ -2151,7 +2152,8 @@ private function registerCacheConfiguration(array $config, ContainerBuilder $con
21512152
if (method_exists(TagAwareAdapter::class, 'setLogger')) {
21522153
$container
21532154
->getDefinition($name)
2154-
->addMethodCall('setLogger', [new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)]);
2155+
->addMethodCall('setLogger', [new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)])
2156+
->addTag('monolog.logger', ['channel' => 'cache']);
21552157
}
21562158

21572159
$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'));

0 commit comments

Comments
 (0)