You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #60011 [DependencyInjection] Enable multiple attribute autoconfiguration callbacks on the same class (GromNaN)
This PR was squashed before being merged into the 7.3 branch.
Discussion
----------
[DependencyInjection] Enable multiple attribute autoconfiguration callbacks on the same class
| Q | A
| ------------- | ---
| Branch? | 7.3
| Bug fix? | yes
| New feature? | yes
| Deprecations? | yes
| Issues | Fixdoctrine/DoctrineBundle#1868 (comment)
| License | MIT
Replace #60001
By having a list of callables for each attributes, we can enable merging definitions each having an autoconfiguration for the same attribute class. This is the case with the `#[Entity]` attribute in DoctrineBundle and FrameworkBundle.
I have to deprecate `ContainerBuilder::getAutoconfiguredAttributes()` as its return type is `array<class-string, callable>`; so I added a new method `AttributeAutoconfigurationPass` that returns `array<class-string, callable[]>` in in order to use reflection on each callable in the compiler pass.
Commits
-------
e36fe60 [DependencyInjection] Enable multiple attribute autoconfiguration callbacks on the same class
thrownewLogicException(\sprintf('Argument "$%s" of attribute autoconfigurator should have a type, use one or more of "\ReflectionClass|\ReflectionMethod|\ReflectionProperty|\ReflectionParameter|\Reflector" in "%s" on line "%d".', $reflectorParameter->getName(), $callableReflector->getFileName(), $callableReflector->getStartLine()));
thrownewLogicException(\sprintf('Argument "$%s" of attribute autoconfigurator should have a type, use one or more of "\ReflectionClass|\ReflectionMethod|\ReflectionProperty|\ReflectionParameter|\Reflector" in "%s" on line "%d".', $reflectorParameter->getName(), $callableReflector->getFileName(), $callableReflector->getStartLine()));
56
-
}
57
58
58
-
try {
59
-
$attributeReflector = new \ReflectionClass($attributeName);
60
-
} catch (\ReflectionException) {
61
-
continue;
62
-
}
59
+
try {
60
+
$attributeReflector = new \ReflectionClass($attributeName);
if (!\in_array('Reflection'.ucfirst($symbol), $types, true)) {
70
-
continue;
71
-
}
72
-
if (!($targets & \constant('Attribute::TARGET_'.strtoupper($symbol)))) {
73
-
thrownewLogicException(\sprintf('Invalid type "Reflection%s" on argument "$%s": attribute "%s" cannot target a '.$symbol.' in "%s" on line "%d".', ucfirst($symbol), $reflectorParameter->getName(), $attributeName, $callableReflector->getFileName(), $callableReflector->getStartLine()));
if (!\in_array('Reflection' . ucfirst($symbol), $types, true)) {
71
+
continue;
72
+
}
73
+
if (!($targets & \constant('Attribute::TARGET_' . strtoupper($symbol)))) {
74
+
thrownewLogicException(\sprintf('Invalid type "Reflection%s" on argument "$%s": attribute "%s" cannot target a ' . $symbol . ' in "%s" on line "%d".', ucfirst($symbol), $reflectorParameter->getName(), $attributeName, $callableReflector->getFileName(), $callableReflector->getStartLine()));
if (isset($this->autoconfiguredAttributes[$attribute])) {
722
-
thrownewInvalidArgumentException(\sprintf('"%s" has already been autoconfigured and merge() does not support merging autoconfiguration for the same attribute.', $attribute));
trigger_deprecation('symfony/dependency-injection', '7.3', 'The "%s()" method is deprecated, use "getAttributeAutoconfigurators()" instead.', __METHOD__);
thrownewLogicException(\sprintf('The "%s" attribute has %d configurators. Use "getAttributeAutoconfigurators()" to get all of them.', $attribute, count($configurators)));
$this->expectUserDeprecationMessage('Since symfony/dependency-injection 7.3: The "Symfony\Component\DependencyInjection\ContainerBuilder::getAutoconfiguredAttributes()" method is deprecated, use "getAttributeAutoconfigurators()" instead.');
0 commit comments