10000 [DependencyInjection] Skip parameter attribute configurators in AttributeAutoconfigurationPass if we can't get the constructor reflector by fancyweb · Pull Request #44385 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DependencyInjection] Skip parameter attribute configurators in AttributeAutoconfigurationPass if we can't get the constructor reflector #44385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files. 8000
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;

/**
* @author Alexander M. Turek <me@derrabus.de>
Expand Down Expand Up @@ -99,11 +100,19 @@ protected function processValue($value, bool $isRoot = false)
}
}

if ($this->parameterAttributeConfigurators && $constructorReflector = $this->getConstructor($value, false)) {
foreach ($constructorReflector->getParameters() as $parameterReflector) {
foreach ($parameterReflector->getAttributes() as $attribute) {
if ($configurator = $this->parameterAttributeConfigurators[$attribute->getName()] ?? null) {
$configurator($conditionals, $attribute->newInstance(), $parameterReflector);
if ($this->parameterAttributeConfigurators) {
try {
$constructorReflector = $this->getConstructor($value, false);
} catch (RuntimeException $e) {
$constructorReflector = null;
}

if ($constructorReflector) {
foreach ($constructorReflector->getParameters() as $parameterReflector) {
foreach ($parameterReflector->getAttributes() as $attribute) {
if ($configurator = $this->parameterAttributeConfigurators[$attribute->getName()] ?? null) {
$configurator($conditionals, $attribute->newInstance(), $parameterReflector);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,11 @@ static function (ChildDefinition $definition, CustomParameterAttribute $attribut
->setPublic(true)
->setAutoconfigured(true);

$container->register('failing_factory', \stdClass::class);
$container->register('ccc', TaggedService4::class)
->setFactory([new Reference('failing_factory'), 'create'])
->setAutoconfigured(true);

$collector = new TagCollector();
$container->addCompilerPass($collector);

Expand All @@ -996,6 +1001,17 @@ static function (ChildDefinition $definition, CustomParameterAttribute $attribut
['property' => 'name'],
['someAttribute' => 'on name', 'priority' => 0, 'property' => 'name'],
],
'ccc' => [
['class' => TaggedService4::class],
['method' => 'fooAction'],
['someAttribute' => 'on fooAction', 'priority' => 0, 'method' => 'fooAction'],
['parameter' => 'param1'],
['someAttribute' => 'on param1 in fooAction', 'priority' => 0, 'parameter' => 'param1'],
['method' => 'barAction'],
['someAttribute' => 'on barAction', 'priority' => 0, 'method' => 'barAction'],
['property' => 'name'],
['someAttribute' => 'on name', 'priority' => 0, 'property' => 'name'],
],
], $collector->collectedTags);
}

Expand Down
0