Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[DependencyInjection] Enable multiple attribute autoconfiguration callbacks on the same class #60011

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
Mar 21, 2025

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Mar 20, 2025

Q A
Branch? 7.3
Bug fix? yes
New feature? yes
Deprecations? yes
Issues Fix doctrine/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 getAttributeAutoconfigurations that returns array<class-string, callable[]> in in order to use reflection on each callable in the compiler pass.

@carsonbot carsonbot added this to the 7.3 milestone Mar 20, 2025
@carsonbot carsonbot changed the title [DependencyInjection] Enable multiple attribute autoconfiguration callbacks on the same class [DependencyInjection] Enable multiple attribute autoconfiguration callbacks on the same class Mar 20, 2025
return $configurators[0];
}

return static function (...$args) use ($configurators) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this work when inspected by reflection?

Copy link
Member Author

@GromNaN GromNaN Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but the compiler pass uses the initial list of callbacks that is returned by the new getAttributeConfigurators() method instead of this.
This is only for backward compatibility if someone calls a callable returned by getAutoconfiguredAttributes(), which is deprecated.

Copy link
Member

@nicolas-grekas nicolas-grekas Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about throwing instead? wouldn't this mimic the previous exception close enough?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM. PR updated.

@@ -1448,7 +1447,7 @@ public function registerForAutoconfiguration(string $interface): ChildDefinition
*/
public function registerAttributeForAutoconfiguration(string $attributeClass, callable $configurator): void
{
$this->autoconfiguredAttributes[$attributeClass] = $configurator;
$this->autoconfiguredAttributes[$attributeClass][] = $configurator;
Copy link
Member Author

@GromNaN GromNaN Mar 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a behavior change: before, it was possible to call registerAttributeForAutoconfiguration() multiple times, replacing the previous configuration. With this change, they are added.

I don't know yet how to handle that, exempt if we allow multiple configurators only by merging.

UPGRADE-7.3.md Outdated Show resolved Hide resolved
@nicolas-grekas
Copy link
Member

Thank you @GromNaN.

@nicolas-grekas nicolas-grekas merged commit caa6d0e into symfony:7.3 Mar 21, 2025
1 check passed
@GromNaN GromNaN deleted the merging branch March 21, 2025 17:38
@fabpot fabpot mentioned this pull request May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.