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

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

Merged
merged 1 commit into from Jan 1, 2022

Conversation

@ogizanagi
Copy link
Member

@ogizanagi ogizanagi commented Dec 28, 2021

Q A
Branch? 6.1
Bug fix? no
New feature? yes
Deprecations? no
Tickets N/A
License MIT
Doc PR Todo

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.

This core resolver aims to resolve backed enum from route path parameters, so we assume a 404 Not Found should be thrown on an invalid backing value provided.

@ogizanagi ogizanagi force-pushed the backed-enum-resolver branch from f5c19a9 to a92f56f Dec 29, 2021
@ogizanagi ogizanagi force-pushed the backed-enum-resolver branch from c5eeca7 to a92f56f Dec 29, 2021
nicolas-grekas added a commit that referenced this issue Dec 29, 2021
…8.1 classes (ogizanagi)

This PR was merged into the 4.4 branch.

Discussion
----------

Suppress psalm error for UndefinedDocblockClass for PHP 8.1 classes

| Q             | A
| ------------- | ---
| Branch?       | 4.4 <!-- see below -->
| Bug fix?      | no
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | #44831 (comment) <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License       | MIT
| Doc PR        | N/A

Same as #43050 for inlined docblock comments (mainly `class-string<FQCN>`)

Commits
-------

dbc3eea Suppress psalm error for UndefinedDocblockClass for PHP 8.1 classes
@ogizanagi ogizanagi force-pushed the backed-enum-resolver branch from a92f56f to 48a9d02 Dec 30, 2021
fabpot
fabpot approved these changes Jan 1, 2022
@fabpot fabpot force-pushed the backed-enum-resolver branch from 48a9d02 to 8466cfe Jan 1, 2022
@fabpot
Copy link
Member

@fabpot fabpot commented Jan 1, 2022

Thank you @ogizanagi.

@fabpot fabpot merged commit a0eecdf into symfony:6.1 Jan 1, 2022
7 of 9 checks passed
@ogizanagi ogizanagi deleted the backed-enum-resolver branch Jan 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants