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

[FrameworkBundle] Autoconfigure ORM attributes only if not done by DoctrineBundle#60001

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

Conversation

GromNaN
Copy link
Member

@GromNaNGromNaN commentedMar 18, 2025
edited
Loading

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

An attribute cannot have multiple autoconfiguration callbacks registered. By excluding classes with the#[Entity] and other ORM attributes in both FrameworkBundle (#59987) and DoctrineBundle (doctrine/DoctrineBundle#1868), the following exception is thrown:

Symfony\Component\DependencyInjection\Exception\InvalidArgumentException: "Doctrine\ORM\Mapping\Embeddable" has already been autoconfigured and merge() does not support merging autoconfiguration for the same attribute.

});

// DoctrineBundle autoconfigures attributes since version 2.14.0
if (!array_key_exists(Entity::class, $container->getAutoconfiguredAttributes())) {
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I'm not sure this is resilient if theDoctrineBundle is registered beforeFrameworkBundle. We can check the package version instead.

Suggested change
if (!array_key_exists(Entity::class,$container->getAutoconfiguredAttributes())) {
if (InstalledVersions::isInstalled('doctrine/doctrine-bundle') &&version_compare(InstalledVersions::getVersion('doctrine/doctrine-bundle'),'2.14.0','<')) {

Copy link
Member

Choose a reason for hiding this comment

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

this is not resilient at all irrespective of the order, because DI extensions receive a separate container builder (which is then merged into the main one), precisely to reduce the cases of writing logic that depends on the order (which is not guaranteed at all by Flex)

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Is the composer version check better?

@@ -21,7 +21,7 @@
"ext-xml": "*",
"symfony/cache": "^6.4|^7.0",
"symfony/config": "^7.3",
"symfony/dependency-injection": "^7.2",
"symfony/dependency-injection": "^7.3",
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

addExcludeTag was added in version 7.3 by#59704

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Alternative to#59999

@nicolas-grekas
Copy link
Member

merge() does not support merging autoconfiguration for the same attribute.

maybe we can improve this instead?
merging should be just about creating a closure that calls all autoconfiguration closures in chain, don't you think?

If we keep the current approach, we should use a feature test if possible.

@GromNaN
Copy link
MemberAuthor

GromNaN commentedMar 20, 2025
edited
Loading

merging should be just about creating a closure that calls all autoconfiguration closures in chain, don't you think?

We use reflection on the closure. Creating a closure programmatically with a different list of arguments would be very complex.

foreach ($container->getAutoconfiguredAttributes()as$attributeName =>$callable) {
$callableReflector =new \ReflectionFunction($callable(...));
if ($callableReflector->getNumberOfParameters() <=2) {
$this->classAttributeConfigurators[$attributeName] =$callable;

Instead,ContainerBuilder::getAutoconfiguredAttributes() could return a list of closures for each attribute. But that would be a BC break.

This issue was anticipated when the feature was introduced:#39897 (comment)

@GromNaN
Copy link
MemberAuthor

New feature in a new PR:#60011

@GromNaNGromNaN deleted the conditional-doctrine-exclude-attributes branchMarch 20, 2025 14:11
nicolas-grekas added a commit that referenced this pull requestMar 21, 2025
…nfiguration 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       | MITReplace#60001By 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
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@stofstofstof left review comments

@chalasrchalasrchalasr approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
7.3
Development

Successfully merging this pull request may close these issues.

5 participants
@GromNaN@nicolas-grekas@stof@chalasr@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp