Skip to content

Commit a569d34

Browse files
committed
minor #16363 [HttpKernel] Add a controller argument resolver for backed 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
2 parents 18612c3 + 12f72b6 commit a569d34

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

controller/argument_value_resolver.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ Built-In Value Resolvers
2020
Symfony ships with the following value resolvers in the
2121
:doc:`HttpKernel component </components/http_kernel>`:
2222

23+
:class:`Symfony\\Component\\HttpKernel\\Controller\\ArgumentResolver\\BackedEnumValueResolver`
24+
Attempts to resolve a backed enum case from a route path parameter that matches the name of the argument.
25+
Leads to a 404 Not Found response if the value isn't a valid backing value for the enum type.
26+
2327
:class:`Symfony\\Component\\HttpKernel\\Controller\\ArgumentResolver\\RequestAttributeValueResolver`
2428
Attempts to find a request attribute that matches the name of the argument.
2529

0 commit comments

Comments
 (0)