Skip to content

Commit 145fc91

Browse files
Merge branch '6.3' into 6.4
* 6.3: [AssetMapper] Fixing bug where a circular exception could be thrown while making error message Dump Valid constaints on debug command #46544 [DependencyInjection] fix dump xml with array/object/enum default value [HttpFoundation] Add a slightly more verbose comment about a warning on UploadedFile [Messenger] BatchHandlerTrait - fix phpdoc typo [SecurityBundle] Remove unused test files Allow passing an `inline_service` to a `service_locator` [Security] Fix error with lock_factory in login_throttling fix(console): fix section output when multiples section with max height Remove me from CODEOWNERS Fix invalid method call + improve exception message Always return bool from messenger amqp conncetion nack [FrameworkBundle] Fix xsd handle-all-throwables [Console] Fix linewraps in OutputFormatter
2 parents db2a88b + a0cee96 commit 145fc91

20 files changed

+206
-2
lines changed

Compiler/AutowirePass.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,17 @@ private function autowireCalls(\ReflectionClass $reflectionClass, bool $isRoot,
235235
unset($arguments[$j]);
236236
$arguments[$namedArguments[$j]] = $value;
237237
}
238-
if ($namedArguments || !$value instanceof $this->defaultArgument) {
238+
if (!$value instanceof $this->defaultArgument) {
239239
continue;
240240
}
241241

242242
if (\is_array($value->value) ? $value->value : \is_object($value->value)) {
243243
unset($arguments[$j]);
244244
$namedArguments = $value->names;
245+
}
246+
247+
if ($namedArguments) {
248+
unset($arguments[$j]);
245249
} else {
246250
$arguments[$j] = $value->value;
247251
}

Loader/Configurator/ContainerConfigurator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ function inline_service(string $class = null): InlineServiceConfigurator
119119
/**
120120
* Creates a service locator.
121121
*
122-
* @param ReferenceConfigurator[] $values
122+
* @param array<ReferenceConfigurator|InlineServiceConfigurator> $values
123123
*/
124124
function service_locator(array $values): ServiceLocatorArgument
125125
{

Tests/Compiler/ServiceLocatorTagPassTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public function testProcessValue()
7070
new Reference('bar'),
7171
new Reference('baz'),
7272
'some.service' => new Reference('bar'),
73+
'inlines.service' => new Definition(CustomDefinition::class),
7374
]])
7475
->addTag('container.service_locator')
7576
;
@@ -82,6 +83,7 @@ public function testProcessValue()
8283
$this->assertSame(CustomDefinition::class, $locator('bar')::class);
8384
$this->assertSame(CustomDefinition::class, $locator('baz')::class);
8485
$this->assertSame(CustomDefinition::class, $locator('some.service')::class);
86+
$this->assertSame(CustomDefinition::class, \get_class($locator('inlines.service')));
8587
}
8688

8789
public function testServiceWithKeyOverwritesPreviousInheritedKey()

Tests/Dumper/XmlDumperTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@
1717
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
1818
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
1919
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
20+
use Symfony\Component\DependencyInjection\Compiler\AutowirePass;
2021
use Symfony\Component\DependencyInjection\ContainerBuilder;
2122
use Symfony\Component\DependencyInjection\ContainerInterface;
2223
use Symfony\Component\DependencyInjection\Dumper\XmlDumper;
2324
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
2425
use Symfony\Component\DependencyInjection\Reference;
26+
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooClassWithDefaultArrayAttribute;
27+
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooClassWithDefaultEnumAttribute;
28+
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooClassWithDefaultObjectAttribute;
2529
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooClassWithEnumAttribute;
2630
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooUnitEnum;
2731
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooWithAbstractArgument;
@@ -278,6 +282,32 @@ public function testDumpHandlesEnumeration()
278282
$this->assertEquals(file_get_contents(self::$fixturesPath.'/xml/services_with_enumeration.xml'), $dumper->dump());
279283
}
280284

285+
/**
286+
* @dataProvider provideDefaultClasses
287+
*/
288+
public function testDumpHandlesDefaultAttribute($class, $expectedFile)
289+
{
290+
$container = new ContainerBuilder();
291+
$container
292+
->register('foo', $class)
293+
->setPublic(true)
294+
->setAutowired(true)
295+
->setArguments([2 => true]);
296+
297+
(new AutowirePass())->process($container);
298+
299+
$dumper = new XmlDumper($container);
300+
301+
$this->assertSame(file_get_contents(self::$fixturesPath.'/xml/'.$expectedFile), $dumper->dump());
302+
}
303+
304+
public static function provideDefaultClasses()
305+
{
306+
yield [FooClassWithDefaultArrayAttribute::class, 'services_with_default_array.xml'];
307+
yield [FooClassWithDefaultObjectAttribute::class, 'services_with_default_object.xml'];
308+
yield [FooClassWithDefaultEnumAttribute::class, 'services_with_default_enumeration.xml'];
309+
}
310+
281311
public function testDumpServiceWithAbstractArgument()
282312
{
283313
$container = new ContainerBuilder();

Tests/Dumper/YamlDumperTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@
1717
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
1818
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
1919
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
20+
use Symfony\Component\DependencyInjection\Compiler\AutowirePass;
2021
use Symfony\Component\DependencyInjection\ContainerBuilder;
2122
use Symfony\Component\DependencyInjection\ContainerInterface;
2223
use Symfony\Component\DependencyInjection\Definition;
2324
use Symfony\Component\DependencyInjection\Dumper\YamlDumper;
2425
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
2526
use Symfony\Component\DependencyInjection\Reference;
27+
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooClassWithDefaultArrayAttribute;
28+
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooClassWithDefaultEnumAttribute;
29+
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooClassWithDefaultObjectAttribute;
2630
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooClassWithEnumAttribute;
2731
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooUnitEnum;
2832
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooWithAbstractArgument;
@@ -162,6 +166,34 @@ public function testDumpHandlesEnumeration()
162166
$this->assertEquals(file_get_contents(self::$fixturesPath.'/yaml/services_with_enumeration.yml'), $dumper->dump());
163167
}
164168

169+
/**
170+
* @requires PHP 8.1
171+
*
172+
* @dataProvider provideDefaultClasses
173+
*/
174+
public function testDumpHandlesDefaultAttribute($class, $expectedFile)
175+
{
176+
$container = new ContainerBuilder();
177+
$container
178+
->register('foo', $class)
179+
->setPublic(true)
180+
->setAutowired(true)
181+
->setArguments([2 => true]);
182+
183+
(new AutowirePass())->process($container);
184+
185+
$dumper = new YamlDumper($container);
186+
187+
$this->assertSame(file_get_contents(self::$fixturesPath.'/yaml/'.$expectedFile), $dumper->dump());
188+
}
189+
190+
public static function provideDefaultClasses()
191+
{
192+
yield [FooClassWithDefaultArrayAttribute::class, 'services_with_default_array.yml'];
193+
yield [FooClassWithDefaultObjectAttribute::class, 'services_with_default_object.yml'];
194+
yield [FooClassWithDefaultEnumAttribute::class, 'services_with_default_enumeration.yml'];
195+
}
196+
165197
public function testDumpServiceWithAbstractArgument()
166198
{
167199
$container = new ContainerBuilder();
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
4+
5+
class FooClassWithDefaultArrayAttribute
6+
{
7+
public function __construct(
8+
array $array = ['a', 'b', 'c'],
9+
bool $firstOptional = false,
10+
bool $secondOptional = false
11+
) {}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
4+
5+
class FooClassWithDefaultEnumAttribute
6+
{
7+
public function __construct(
8+
FooUnitEnum $enum = FooUnitEnum::FOO,
9+
bool $firstOptional = false,
10+
bool $secondOptional = false,
11+
) {}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
4+
5+
class FooClassWithDefaultObjectAttribute
6+
{
7+
public function __construct(
8+
object $object = new \stdClass(),
9+
bool $firstOptional = false,
10+
bool $secondOptional = false,
11+
) {}
12+
}

Tests/Fixtures/config/services_with_service_locator_argument.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,10 @@
2626
'foo' => service('foo_service'),
2727
service('bar_service'),
2828
])]);
29+
30+
$services->set('locator_dependent_inline_service', \ArrayObject::class)
31+
->args([service_locator([
32+
'foo' => inline_service(\stdClass::class),
33+
'bar' => inline_service(\stdClass::class),
34+
])]);
2935
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">
3+
<services>
4+
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerInterface" public="true" synthetic="true"/>
5+
<service id="foo" class="Symfony\Component\DependencyInjection\Tests\Fixtures\FooClassWithDefaultArrayAttribute" public="true" autowire="true">
6+
<argument key="secondOptional">true</argument>
7+
</service>
8+
</services>
9+
</container>

0 commit comments

Comments
 (0)