Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

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

Sign up
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nicolas-grekas merged 1 commit intosymfony:7.3fromGromNaN:merging
Mar 21, 2025

Conversation

GromNaN
Copy link
Member

@GromNaNGromNaN commentedMar 20, 2025
edited
Loading

QA
Branch?7.3
Bug fix?yes
New feature?yes
Deprecations?yes
IssuesFixdoctrine/DoctrineBundle#1868 (comment)
LicenseMIT

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 deprecateContainerBuilder::getAutoconfiguredAttributes() as its return type isarray<class-string, callable>; so I added a new methodgetAttributeAutoconfigurations that returnsarray<class-string, callable[]> in in order to use reflection on each callable in the compiler pass.

valtzu reacted with thumbs up emoji
@carsonbotcarsonbot added this to the7.3 milestoneMar 20, 2025
@carsonbotcarsonbot changed the title[DependencyInjection] Enable multiple attribute autoconfiguration callbacks on the same class[DependencyInjection] Enable multiple attribute autoconfiguration callbacks on the same classMar 20, 2025
return $configurators[0];
}

return static function (...$args) use ($configurators) {

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
MemberAuthor

@GromNaNGromNaNMar 20, 2025
edited
Loading

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 newgetAttributeConfigurators() method instead of this.
This is only for backward compatibility if someone calls a callable returned bygetAutoconfiguredAttributes(), which is deprecated.

Copy link
Member

@nicolas-grekasnicolas-grekasMar 20, 2025
edited
Loading

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
MemberAuthor

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
MemberAuthor

@GromNaNGromNaNMar 21, 2025
edited
Loading

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 callregisterAttributeForAutoconfiguration() 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.

@nicolas-grekas
Copy link
Member

Thank you@GromNaN.

@nicolas-grekasnicolas-grekas merged commitcaa6d0e intosymfony:7.3Mar 21, 2025
1 check passed
@GromNaNGromNaN deleted the merging branchMarch 21, 2025 17:38
@fabpotfabpot mentioned this pull requestMay 2, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
7.3
Development

Successfully merging this pull request may close these issues.

3 participants
@GromNaN@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp