Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Routing] Add EnumRequirement to help generate route requirements from a \BackedEnum#45803
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
carsonbot commentedMar 22, 2022
Hey! I think@usu has recently worked with this code. Maybe they can help review this? Cheers! Carsonbot |
ogizanagi commentedMar 22, 2022
Note: the alternative mentioned on Slack was to use a PHP 8 attribute to configure the |
nicolas-grekas commentedMar 22, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
If we really want to support subsets, we should give the subset of "what". Honestly, I find this quite ugly... but 🤷 |
nicolas-grekas commentedMar 28, 2022
What about renaming BackedEnumRequirement to EnumRequirement? I feel like adding "Backed" doesn't provide anything. |
fancyweb commentedMar 31, 2022
I'll change the signature to |
nicolas-grekas commentedMar 31, 2022
It cannot since it will throw once ppl give it a try - and it's a logical error to expect that a pure enum could work as a part of matching a URL, so ppl that could have this expectation are wrong anyway. "BackedEnum" just adds to the ugliness of using enums to me... |
cb68e74 to275d111Compare275d111 toce87606Comparefabpot commentedApr 12, 2022
Thank you@fancyweb. |
tarlepp commentedApr 19, 2022
Similar solution for |
nicolas-grekas commentedJun 21, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Both ways could be supported natively ifphp/php-src#8825 were available, reducing the boilerplate needed for common simple cases. |
Uh oh!
There was an error while loading.Please reload this page.
Ref#44831
I'd like to limit a route parameter allowed values to the backed values of an enum to use it in conjunction with the new
\BackedEnumargument resolver (ie fail from the start).Also, sometimes, I'd like to limit it only to a subset of the backed values.
I couldn't find a way to do that because enums can't implement
__toString()and accessing->valueis not considered a constant operation.We can leverage the fact that route requirements can be a
\Stringable.Before (no enum):
Allow all enum cases:
Allow a subset:
Probably not the best solution but I hope we can find something for that use case for 6.1 😄
cc@ogizanagi