Skip to content

[DependencyInjection] Fix checking for interfaces in ContainerBuilder::getReflectionClass() #58822

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

Conversation

donquixote
Copy link
Contributor

@donquixote donquixote commented Nov 9, 2024

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #58821.
License MIT

Currently, ContainerBuilder::getReflectionClass() supports interfaces only if symfony/config package is present.
With this fix, it will do so without symfony/config.

Always add tests and ensure they pass.

Not sure how to do this.
All tests run in the monorepo, with all packages present, so class_exists(ClassExistenceResource::class) will always be TRUE.
To make this testable, we should make the condition dependent on resource tracking.

Never break backward compatibility (see https://symfony.com/bc).

This is TBD.
This change would enable autowire for some services where this was previously not the case.

@carsonbot
Copy link

Hey!

Thanks for your PR. You are targeting branch "7.2" but it seems your PR description refers to branch "5.4 or 7.2, TBD".
Could you update the PR description or change target branch? This helps core maintainers a lot.

Cheers!

Carsonbot

@carsonbot carsonbot changed the title Issue #58821: [DependencyInjection] Support interfaces in ContainerBuilder::getReflectionClass() [DependencyInjection] Issue #58821: Support interfaces in ContainerBuilder::getReflectionClass() Nov 9, 2024
@derrabus
Copy link
Member

derrabus commented Nov 9, 2024

This looks like a bugfix to me. Please target 5.4.

@donquixote donquixote force-pushed the issue-58821-ContainerBuilder-support-interfaces branch from 6f2be11 to 1c3690b Compare November 10, 2024 01:02
@donquixote donquixote changed the base branch from 7.2 to 5.4 November 10, 2024 01:03
@donquixote
Copy link
Contributor Author

This looks like a bugfix to me. Please target 5.4.

Let's see if there is consensus that this is a bug fix.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

LGTM after some minor changes

@@ -369,7 +369,7 @@ public function getReflectionClass(?string $class, bool $throw = true): ?\Reflec
$resource = new ClassExistenceResource($class, false);
$classReflector = $resource->isFresh(0) ? false : new \ReflectionClass($class);
} else {
$classReflector = class_exists($class) ? new \ReflectionClass($class) : false;
$classReflector = (class_exists($class) || interface_exists($class)) ? new \ReflectionClass($class) : false;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$classReflector = (class_exists($class) || interface_exists($class)) ? new \ReflectionClass($class) : false;
$classReflector = class_exists($class) || interface_exists($class, false) ? new \ReflectionClass($class) : false;

@nicolas-grekas nicolas-grekas modified the milestones: 7.2, 5.4 Nov 13, 2024
@nicolas-grekas nicolas-grekas changed the title [DependencyInjection] Issue #58821: Support interfaces in ContainerBuilder::getReflectionClass() [DependencyInjection] Fix checking for interfaces in ContainerBuilder::getReflectionClass() Nov 14, 2024
@nicolas-grekas nicolas-grekas force-pushed the issue-58821-ContainerBuilder-support-interfaces branch from 1c3690b to 6166e8f Compare November 20, 2024 10:52
@nicolas-grekas
Copy link
Member

Thank you @donquixote.

@nicolas-grekas nicolas-grekas merged commit cf20e09 into symfony:5.4 Nov 20, 2024
10 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants