Skip to content
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

Wire up type aliases support in EntityValueResolver #1790

Open
wants to merge 1 commit into
base: 2.13.x
Choose a base branch
from

Conversation

NanoSector
Copy link
Contributor

@NanoSector NanoSector commented Apr 11, 2024

This is an addendum to PR symfony/symfony#54545 targeted at issue symfony/symfony#51765 in the Symfony Doctrine Bridge, which adds type alias support to EntityValueResolver.

This code injects the doctrine.orm.resolve_target_entities configuration into the EntityValueResolver class.

if (class_exists(EntityValueResolver::class)) {
$valueResolverReflection = new ReflectionClass(EntityValueResolver::class);

if ($valueResolverReflection->hasMethod('addTypeAlias')) {
Copy link
Member

Choose a reason for hiding this comment

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

I think using a constructor argument instead of an adder can save us from using reflection at all. WDYT?

Copy link
Contributor Author

@NanoSector NanoSector Apr 13, 2024

Choose a reason for hiding this comment

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

Initially that is what I tried to do, but I figured explicitly checking support without depending on constructor argument count and order was more desirable. This also seems more in line with other parts of the extension which also call add* or set* methods. I do agree that reflection is generally undesirable.
Having this as a method also allows for easier extension of the ValueResolver beyond the bundle, since the property holding this mapping is otherwise private; although this can also be achieved with explicit service configuration in the framework.

Also, setting the argument on its position by key doesn't seem to work. Replacing the reflection code in this PR with the following snippet:

$valueResolverDefinition->setArgument(3, $config['resolve_target_entities']);

Results in an error: TypeError: Symfony\Bridge\Doctrine\ArgumentResolver\EntityValueResolver::__construct(): Argument #3 ($defaults) must be of type Symfony\Bridge\Doctrine\Attribute\MapEntity, array given
Even when using 4 in the above code snippet. Using explicit argument names (->setArgument('$typeAliases', ...)) doesn't work as this causes a container compilation error on older bridge versions because the argument does not exist; this would break backwards compatibility (or still need reflection to check the existance of the property/argument).

Choose a reason for hiding this comment

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

for add an argument, I think you can remove the condition if ($controllerResolverDefaults) { at l.527 for always declare the mapentity (with default arguments) as arg 2 and then you can decalre a argument 3.

Copy link
Member

Choose a reason for hiding this comment

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

@NanoSector up to give @eltharin's suggestion a try?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nicolas-grekas Sorry, these PRs must have fallen off my radar. I've rebased them on the latest development branches and applied your and @eltharin 's suggestions.

@NanoSector NanoSector requested a review from nicolas-grekas May 1, 2024 13:57
@ostrolucky ostrolucky added the Status: On Hold Most likely waiting for upstream resolution label May 5, 2024
@NanoSector NanoSector force-pushed the feature/type-aliases-support branch from f748096 to 18f1ca0 Compare August 12, 2024 20:41
@NanoSector NanoSector changed the base branch from 2.12.x to 2.13.x August 12, 2024 20:43
This is an addendum to PR symfony/symfony#51765 in the Symfony Doctrine Bridge, which adds type alias support to EntityValueResolver.

This code injects the doctrine.orm.resolve_target_entities configuration into the EntityValueResolver class.
@NanoSector NanoSector force-pushed the feature/type-aliases-support branch from 18f1ca0 to 142a3df Compare August 12, 2024 20:47
@NanoSector
Copy link
Contributor Author

@ostrolucky Sorry to bother you, I am wondering if any action is required on my part, considering the PR still has 'on hold' status? Its Symfony counterpart is marked as ready.

@ostrolucky
Copy link
Member

It's onhold because upstream PR is not merged yet

@ostrolucky ostrolucky force-pushed the 2.13.x branch 3 times, most recently from abb5de0 to 2983fa7 Compare September 29, 2024 08:56
@ostrolucky ostrolucky force-pushed the 2.13.x branch 2 times, most recently from 01c7700 to 7bfb8e8 Compare October 21, 2024 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: On Hold Most likely waiting for upstream resolution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants