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

[RFC][HttpKernel][Security] Allowed adding attributes on controller arguments that will be passed to argument resolvers. #37829

Merged
merged 1 commit into from Sep 12, 2020

Conversation

jvasseur
Copy link
Contributor

@jvasseur jvasseur commented Aug 13, 2020

Q A
Branch? master
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #29692
License MIT
Doc PR Not yet, will do it it this PR is accepted.

This PR allow to configure argument resolvers using PHP8 attributes.

This is basically a fix for #29692 but using a different strategy that the one proposed in the issue:

  • it uses PHP attributes instead of doctrine annotation since they can be added directly on method arguments.
  • it uses a simpler design by just adding the attribute to the ArgumentMetadata and let the individual resolvers decide if they want to react to the presence of the attribute.
  • it uses an attributes classe per use-case instead of an unique Arg annotation.

As an example, I've added (in the second commit) a CurrentUser attribute that allows the UserValueResolver to always inject the current user even if the argument is not typed with the UserInterface (to allow typing your actual class instead for example).

This would allow to do things like this:

class MyController
{
    public function indexAction(#[CurentUser] MyUser $user)
    {
    }
}

@carsonbot carsonbot added Status: Needs Review RFC RFC = Request For Comments (proposals about features that you want to be discussed) HttpKernel Security Feature labels Aug 13, 2020
@jvasseur jvasseur force-pushed the controller-argument-attribute branch 3 times, most recently from cd82a16 to 59e74d8 Compare Aug 19, 2020
@jvasseur jvasseur force-pushed the controller-argument-attribute branch from 59e74d8 to c699230 Compare Aug 25, 2020
@nicolas-grekas nicolas-grekas added this to the next milestone Aug 31, 2020
@jvasseur jvasseur force-pushed the controller-argument-attribute branch from c699230 to 2484a69 Compare Sep 2, 2020
@fabpot
Copy link
Member

fabpot commented Sep 12, 2020

/cc @derrabus

fabpot
fabpot approved these changes Sep 12, 2020
Copy link
Member

@fabpot fabpot left a comment

I'm going to play with it a little but the code LGTM.

…rguments that will be passed to argument resolvers.
@fabpot fabpot force-pushed the controller-argument-attribute branch from 2484a69 to 20f3169 Compare Sep 12, 2020
@fabpot
Copy link
Member

fabpot commented Sep 12, 2020

Thank you @jvasseur.

@fabpot fabpot merged commit a32fde9 into symfony:master Sep 12, 2020
0 of 3 checks passed
@jvasseur jvasseur deleted the controller-argument-attribute branch Sep 12, 2020
@derrabus
Copy link
Member

derrabus commented Sep 12, 2020

Great addition, thanks @jvasseur!

@nicolas-grekas nicolas-grekas removed this from the next milestone Oct 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature HttpKernel RFC RFC = Request For Comments (proposals about features that you want to be discussed) Security Status: Reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC][HttpKernel] Configurable argument value resolvers
5 participants