Skip to content

[HttpKernel] Add a controller argument resolver for backed enums #16363

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

Merged
merged 1 commit into from
Jan 3, 2022

Conversation

ogizanagi
Copy link
Contributor

Fixes #16357

Adding a ref to the BackedEnumValueResolver introduced in 6.1 to https://symfony.com/doc/current/controller/argument_value_resolver.html

Added before RequestAttributeValueResolver since it has a higher priority.

Don't know however where we could showcase such an example:

Given:

namespace App\Model;

enum Suit: string 
{
    case Hearts = 'H';
    case Diamonds = 'D';
    case Clubs = 'C';
    case Spades = 'S';
}

and the controller:

class CardController
{
    #[Route('/cards/{suit}')]
    public function list(Suit $suit): Response
    {
        // [...]
    }
}

A request to /cards/H would inject the Suit::Hearts enum case into the controller $suit argument.

@carsonbot carsonbot added this to the 6.1 milestone Jan 3, 2022
@javiereguiluz javiereguiluz merged commit a569d34 into symfony:6.1 Jan 3, 2022
@ogizanagi ogizanagi deleted the backed-enum-resolver branch January 3, 2022 16:56
@javiereguiluz
Copy link
Member

Maxime, thanks a lot for contributing this doc update. I agree with you that it's difficult to understand this feature without an example (maybe it will be easier when most PHP developers are used to Enums). So, in 4fe62c6 I've added the code example that you proposed.

@ogizanagi
Copy link
Contributor Author

That's great, thank you Javier. 👍🏻
For some reasons, the issue #16357 wasn't closed during merge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants