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

[DoctrineBridge] Add an Entity Argument Resolver#43854

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
fabpot merged 2 commits intosymfony:6.2fromjderusse:doctrine-resolver
Jul 20, 2022

Conversation

jderusse
Copy link
Member

@jderussejderusse commentedOct 31, 2021
edited by nicolas-grekas
Loading

QA
Branch?6.1
Bug fix?no
New feature?yes
Deprecations?no
Ticketspart of#40333
LicenseMIT
Doc PRtodo

This PR provides an Argument Resolver for Doctrine entities.

This would replace the SensioFramework's DoctrineParamConverter (in fact most of the code is copy/pasted from here) and helps users to disable the paramConverter and fix the related issue.

usage:

sensio_framework_extra:request:converters:falseservices:Symfony\Bridge\Doctrine\ArgumentResolver\EntityValueResolver:~
#[Route('/blog/{slug}')]publicfunctionshow(Post$post){}

or with custom options

#[Route('/blog/{id}')]publicfunctionshow(  #[MapEntity(entityManager:'foo', expr:'repository.findNotDeletedById(id)')]Post$post){}

jvasseur, TomasVotruba, kbond, and maxhelias reacted with thumbs up emojistloyd, HypeMC, mbabker, ro0NL, jschaedl, kaznovac, zmitic, TomasVotruba, OskarStark, yceruto, and 4 more reacted with heart emojichalasr, stloyd, chapterjason, wkania, HypeMC, ro0NL, derrabus, kaznovac, TomasVotruba, OskarStark, and 4 more reacted with rocket emoji
@jderussejderusse added this to the6.1 milestoneOct 31, 2021
@carsonbotcarsonbot changed the titleAdd an Entity Argument Resolver[DoctrineBridge] Add an Entity Argument ResolverOct 31, 2021
@carsonbotcarsonbot modified the milestones:6.1,6.0Oct 31, 2021
@jderussejderusseforce-pushed thedoctrine-resolver branch 4 times, most recently frombfff004 to5be70c3CompareOctober 31, 2021 11:13
@fabpotfabpot modified the milestones:6.0,6.1Nov 3, 2021
Copy link
Member

@derrabusderrabus left a comment

Choose a reason for hiding this comment

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

Can we add a constructor flag to make the resolver opt-in? I'd like to keep it dormant unless I use the attribute.

@jderusse
Copy link
MemberAuthor

Can we add a constructor flag to make the resolver opt-in? I'd like to keep it dormant unless I use the attribute.

Added a constructor option that make the resolver ignoring arguments without attribute

derrabus reacted with thumbs up emojiderrabus reacted with heart emoji

Copy link
Member

@derrabusderrabus left a comment

Choose a reason for hiding this comment

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

Looks good so far. About the test: This whole feature is tested with a fully mocked entity manager. Since Doctrine ORM is an external library, this could make the tests brittle and hard to maintain if the ORM changes it's behavior (for whatever reason).

Shall we try to test agains a real EM with an in-memory SQLite DB?

@jderussejderusseforce-pushed thedoctrine-resolver branch 2 times, most recently fromb75c376 to9fa044eCompareDecember 19, 2021 13:53
@stof
Copy link
Member

stof commentedJun 7, 2022

I think the main reason why you see the EM being lazy in most cases is because DoctrineBundle makes the EM lazy to make it resettable (by resetting the proxy), not to lazy-load its dependency graph.

@nicolas-grekas
Copy link
Member

DoctrineBundle makes the EM lazy to make it resettable (by resetting the proxy), not to lazy-load its dependency graph.

Indeed, that answers my concerns!

The conflict between resolvers will be handled by registering the tag with the right priority (like we do for all other argumentResolvers).

I'd like to see this approach before adding an option to opt-in.

I rebased the PR on your fork and submittedjderusse#3 on top.
After that patch, I'll be 👍 as is.

Copy link
Member

@weaverryanweaverryan left a comment

Choose a reason for hiding this comment

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

Approve - other than fabbot.

In DoctrineBundle (where the wiring will live), the entire feature should be opt-in, right? I mean, it shouldrequire some sort ofparam_converter: true config indoctrine.yaml, which we could ship in thedoctrine.yaml recipe. I think that's needed, otherwise I could imagine the auto-enabling of this feature could cause some edge-case weird situations.

derrabus reacted with thumbs up emoji
}
}

private function getOptions(ArgumentMetadata $argument): MapEntity
Copy link
Member

Choose a reason for hiding this comment

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

minor - butgetMapEntity() orgetMapEntityAttribute() might be better - and$mapEntityAttribute instead of$options in the code. But this is purely for the enjoyment of me reading the code ;)

yceruto reacted with thumbs up emoji
6.2
---

* Add `#[MapEntity]` with its corresponding `EntityArgumentResolver`
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
* Add`#[MapEntity]` with its corresponding`EntityArgumentResolver`
* Add`#[MapEntity]` with its corresponding`EntityValueResolver`

Copy link
Member

Choose a reason for hiding this comment

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

fixed inabfdc54

chalasr reacted with thumbs up emoji
@dunglas
Copy link
Member

@weaverryan but when these edge cases appear, users can opt-out.

I prefer to have this kind of feature on by default, this helps making the framework easy to use for newcomers and to make the catchy features more discoverable. This also allow to not bloat the "default" config generated by Flex.

For instance, I would like to enable auto-validation by default. Sure there are some known edge cases, but they are easy to fix by disabling the feature for an entity or a property (require some googling but that's all). On the other hand, with the current situation (not enabled by default), only advanced users leverage this feature while it mostly targets newcomers who except (rightly imho) to not have to duplicate similar metadata (ORM, validation, PHPDoc...).

Bundles should be opiniated but configurable, enabling by default features with a high DX value like this one is a huge one for newcomers and for the simplicity of use of the framework.

@chalasr
Copy link
Member

I’d at least make it explicitly opt-in when FrameworkExtraBundle is installed to prevent any conflicting situations or ambiguity

@derrabus
Copy link
Member

I prefer to have this kind of feature on by default

I agree, the question is where this "on by default" happens. I'd prefer it to happen in the recipe which would make it consistent with other magic behavior like autowiring. And we would also make the "off switch" discoverable.

@dunglas
Copy link
Member

dunglas commentedJul 14, 2022
edited
Loading

The verbose config that we generate per default just to enable these features increase the perceived complexity of Symfony. Take a look at the default services.yaml file, it can be a bit scary and discouraging for newcomers just starting a new project.

IMHO the DX is better is it just works with as few generated config as possible by default, but you can tweak every features by reading the documentation.

jderusseand others added2 commitsJuly 20, 2022 19:10
Co-authored-by: Jérémy Derussé <jeremy@derusse.com>
@fabpot
Copy link
Member

Thank you@jderusse.

@janklan
Copy link

I know this comment is coming rather late and possibly a bit off-topic, but I'm wondering if the converting behaviour I described in#47166 is a bug or a feature and may be worth addressing during the transition from SensioFrameworkExtraBundle to the new resolver?

@nicolas-grekas
Copy link
Member

I openeddoctrine/DoctrineBundle#1554 to wire this into doctrine-bundle.

@jderussejderusse deleted the doctrine-resolver branchOctober 12, 2022 15:20
@fabpotfabpot mentioned this pull requestOct 24, 2022
jasperweyne added a commit to jasperweyne/helpless-kiwi that referenced this pull requestNov 23, 2022
This reverts commitd92865d. This isnecessary persymfony/symfony#40333, sinceLocalAccount is both a Doctrine entity and the CurrentUser class, whichis a won'tfix for the FrameworkExtraBundle. With Symfony 6.2, this willbe fixed by the EntityArgumentResolver(symfony/symfony#43854). Until then, let's stickto what we have.
@Nugjii

This comment was marked as off-topic.

@ruudk

This comment was marked as off-topic.

@symfonysymfony locked asresolvedand limited conversation to collaboratorsDec 12, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@stofstofstof left review comments

@jvasseurjvasseurjvasseur left review comments

@xabbuhxabbuhxabbuh left review comments

@ismail1432ismail1432ismail1432 left review comments

@dunglasdunglasdunglas approved these changes

@weaverryanweaverryanweaverryan approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@derrabusderrabusderrabus approved these changes

@chalasrchalasrchalasr approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
6.2
Development

Successfully merging this pull request may close these issues.

17 participants
@jderusse@codedmonkey@nicolas-grekas@derrabus@Hanmac@weaverryan@chalasr@dunglas@stof@fabpot@janklan@Nugjii@ruudk@jvasseur@xabbuh@ismail1432@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp