- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 9.7k
[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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
bfff004    to
    5be70c3      
    Compare
  
    There was a problem hiding this 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.
        
          
                src/Symfony/Bridge/Doctrine/ArgumentResolver/EntityValueResolver.php
              
                Outdated
          
            Show resolved
            Hide resolved
        
      5be70c3    to
    bfa695d      
    Compare
  
    | 
 Added a constructor option that make the resolver ignoring arguments without attribute | 
bfa695d    to
    b1d8c64      
    Compare
  
            
          
                src/Symfony/Bridge/Doctrine/ArgumentResolver/EntityValueResolver.php
              
                Outdated
          
            Show resolved
            Hide resolved
        
      b1d8c64    to
    45c19b0      
    Compare
  
    45c19b0    to
    1f384e9      
    Compare
  
    1f384e9    to
    1656018      
    Compare
  
    There was a problem hiding this 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?
        
          
                src/Symfony/Bridge/Doctrine/ArgumentResolver/EntityValueResolver.php
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/Symfony/Bridge/Doctrine/ArgumentResolver/EntityValueResolver.php
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/Symfony/Bridge/Doctrine/ArgumentResolver/EntityValueResolver.php
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/Symfony/Bridge/Doctrine/Tests/ArgumentResolver/EntityValueResolverTest.php
              
                Outdated
          
            Show resolved
            Hide resolved
        
      b75c376    to
    9fa044e      
    Compare
  
            
          
                src/Symfony/Bridge/Doctrine/ArgumentResolver/EntityValueResolver.php
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/Symfony/Bridge/Doctrine/ArgumentResolver/EntityValueResolver.php
              
                Outdated
          
            Show resolved
            Hide resolved
        
      | 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. | 
8d3245c    to
    a9f09ae      
    Compare
  
    | 
 Indeed, that answers my concerns! 
 I'd like to see this approach before adding an option to opt-in. I rebased the PR on your fork and submitted jderusse#3 on top. | 
There was a problem hiding this 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 should require some sort of param_converter: true config in doctrine.yaml, which we could ship in the doctrine.yaml recipe. I think that's needed, otherwise I could imagine the auto-enabling of this feature could cause some edge-case weird situations.
| } | ||
| } | ||
|  | ||
| private function getOptions(ArgumentMetadata $argument): MapEntity | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor - but getMapEntity() or getMapEntityAttribute() might be better - and $mapEntityAttribute instead of $options in the code. But this is purely for the enjoyment of me reading the code ;)
| 6.2 | ||
| --- | ||
|  | ||
| * Add `#[MapEntity]` with its corresponding `EntityArgumentResolver` | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * Add `#[MapEntity]` with its corresponding `EntityArgumentResolver` | |
| * Add `#[MapEntity]` with its corresponding `EntityValueResolver` | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in abfdc54
| @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. | 
| I’d at least make it explicitly opt-in when FrameworkExtraBundle is installed to prevent any conflicting situations or ambiguity | 
| 
 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. | 
| 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. | 
Co-authored-by: Jérémy Derussé <jeremy@derusse.com>
0966e43    to
    5a3df5e      
    Compare
  
    | Thank you @jderusse. | 
| 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? | 
| I opened doctrine/DoctrineBundle#1554 to wire this into doctrine-bundle. | 
This reverts commit d92865d. This is necessary per symfony/symfony#40333, since LocalAccount is both a Doctrine entity and the CurrentUser class, which is a won'tfix for the FrameworkExtraBundle. With Symfony 6.2, this will be fixed by the EntityArgumentResolver (symfony/symfony#43854). Until then, let's stick to what we have.
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:
or with custom options