-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Routing] Support PHP 8.1 enums as route name
#44563
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
Comments
Why? I feel like there would be no benefits to use an enum here personally. At least I don't see any yet. |
The purpose might be to remove this "SomeUselessStringThatNobodyNeeds". If route name can be enum values, the UrlGenerator will have to support them. And that add a new challenge to generate a URL in Twig. |
Benefits:
|
The URL generator uses route names as array keys in the dumped cache code, allowing to get the route info in |
To me, enums are useful to restrict possibilities to a range of limited values. Route names don't fall in this category. |
As much as I'd like to explore the possible uses of enums further: I agree with @nicolas-grekas that enums are not useful here. I wouldn't store route names in constants either, btw. The proposed changed would introduce complexity for now real benefit. |
Let's close because we aready have downvotes from several core team members. Thanks for the proposal though. |
Yeah, closing is OK. Just one more question: How do you guys manage your route names then? I was thinking the |
php/php-src#8825 could be a solution here, allowing seamless compatibility between enumerated routes and the routing component. |
An even better idea would be to allow getting rid of the |
Description
I'm trying to avoid strings as Route
name
, so I've created aPage
class that holdsconst
s for it:Controller:
I think this would be a perfect use-case for a pure enum:
Controller:
#[Route(path: '/', name: Page::Home)]
Right now, this leads to:
Example
No response
The text was updated successfully, but these errors were encountered: