Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

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

Closed
fabpot opened this issue Jan 1, 2022 · 1 comment
Closed

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

fabpot opened this issue Jan 1, 2022 · 1 comment

Comments

@fabpot
Copy link
Member

fabpot commented Jan 1, 2022

Q A
Feature PR symfony/symfony#44831
PR author(s) @ogizanagi
Merged in 6.1
javiereguiluz added a commit that referenced this issue Jan 3, 2022
…ed enums (ogizanagi)

This PR was merged into the 6.1 branch.

Discussion
----------

[HttpKernel] Add a controller argument resolver for backed enums

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:

```php
namespace App\Model;

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

and the controller:

```php
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.

Commits
-------

12f72b6 [HttpKernel] Add a controller argument resolver for backed enums
@javiereguiluz
Copy link
Member

Closing as fixed by #16363.

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

No branches or pull requests

3 participants