Skip to content

Commit 81748f3

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: Add missing files from 5.3 Remove unneeded files Tweak bug report template Prevent infinite nesting of lazy `ObjectManager` instances when `ObjectManager` is reset [DependencyInjection] Skip parameter attribute configurators in AttributeAutoconfigurationPass if we can't get the constructor reflector [HttpKernel] fix sending Vary: Accept-Language when appropriate
2 parents f079a87 + 9bd1ef3 commit 81748f3

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

Compiler/AttributeAutoconfigurationPass.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
1616
use Symfony\Component\DependencyInjection\Definition;
1717
use Symfony\Component\DependencyInjection\Exception\LogicException;
18+
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
1819

1920
/**
2021
* @author Alexander M. Turek <me@derrabus.de>
@@ -99,11 +100,19 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
99100
}
100101
}
101102

102-
if ($this->parameterAttributeConfigurators && $constructorReflector = $this->getConstructor($value, false)) {
103-
foreach ($constructorReflector->getParameters() as $parameterReflector) {
104-
foreach ($parameterReflector->getAttributes() as $attribute) {
105-
if ($configurator = $this->parameterAttributeConfigurators[$attribute->getName()] ?? null) {
106-
$configurator($conditionals, $attribute->newInstance(), $parameterReflector);
103+
if ($this->parameterAttributeConfigurators) {
104+
try {
105+
$constructorReflector = $this->getConstructor($value, false);
106+
} catch (RuntimeException $e) {
107+
$constructorReflector = null;
108+
}
109+
110+
if ($constructorReflector) {
111+
foreach ($constructorReflector->getParameters() as $parameterReflector) {
112+
foreach ($parameterReflector->getAttributes() as $attribute) {
113+
if ($configurator = $this->parameterAttributeConfigurators[$attribute->getName()] ?? null) {
114+
$configurator($conditionals, $attribute->newInstance(), $parameterReflector);
115+
}
107116
}
108117
}
109118
}

Tests/Compiler/IntegrationTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,11 @@ static function (ChildDefinition $definition, CustomAnyAttribute $attribute, \Re
932932
->setPublic(true)
933933
->setAutoconfigured(true);
934934

935+
$container->register('failing_factory', \stdClass::class);
936+
$container->register('ccc', TaggedService4::class)
937+
->setFactory([new Reference('failing_factory'), 'create'])
938+
->setAutoconfigured(true);
939+
935940
$collector = new TagCollector();
936941
$container->addCompilerPass($collector);
937942

@@ -952,6 +957,17 @@ static function (ChildDefinition $definition, CustomAnyAttribute $attribute, \Re
952957
['property' => 'name'],
953958
['someAttribute' => 'on name', 'priority' => 0, 'property' => 'name'],
954959
],
960+
'ccc' => [
961+
['class' => TaggedService4::class],
962+
['method' => 'fooAction'],
963+
['someAttribute' => 'on fooAction', 'priority' => 0, 'method' => 'fooAction'],
964+
['parameter' => 'param1'],
965+
['someAttribute' => 'on param1 in fooAction', 'priority' => 0, 'parameter' => 'param1'],
966+
['method' => 'barAction'],
967+
['someAttribute' => 'on barAction', 'priority' => 0, 'method' => 'barAction'],
968+
['property' => 'name'],
969+
['someAttribute' => 'on name', 'priority' => 0, 'property' => 'name'],
970+
],
955971
], $collector->collectedTags);
956972
}
957973

0 commit comments

Comments
 (0)