-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
cleanup: use roles constants #1404
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
Conversation
c6dcbcd
to
6da7f01
Compare
Could we use an Enum instead of constants? Would Enums work everywhere? Is it worth it or is it overengineering? |
No we cannot. Roles are strings in Symfony, not an enum object. |
6da7f01
to
1a27dce
Compare
1a27dce
to
b31c0ae
Compare
You can use e.g. |
Hello, is it OK for this PR? Or should we close it? |
My opinion:
What do others think about this? Thanks. |
I fully agree with @javiereguiluz' assessment.
Me too, I wouldn't make those constants members of the
Me neither and I wouldn't do it tbh. We don't gain much here.
Same. I would revert this as well. |
Sure you can workaround the bad architecture by using |
@stof but in this case we're not talking about enums. It's using PHP constants in YAML that looks too complicated to us. E.g. this change: role_hierarchy:
- ROLE_ADMIN: ROLE_USER
+ !php/const App\Entity\User::ROLE_ADMIN: !php/const App\Entity\User::ROLE_USER But in PHP files these constants look very nice. |
But that looks weird to put this in a separated class. In this case, we should use an enum (but we don't want too here). Having these constants in the User class is the more pragmatic way, IMHO.
Actually, if we don't want to use a constant here, we could use a twig extension to do the job and make use of the PHP constant. But that's not as simple as using I remember now, that was the opportunity to show the usage of the Twig globals.
I agree, it makes the YAML unreadable. I didn't even know it was possible to do this, so let's revert this. It was a try. |
0f992ac
to
1c40029
Compare
🤨 🤷🏻♂️ |
1c40029
to
5b74809
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this proposal a lot. Thanks Loïc!
It's merged now. Thanks! |
5b74809
to
f057af8
Compare
Before we had to hard-code roles strings:
But with attributes, can use constants. I find this cleaner. I have already used this on several projects and I didn't find drawbacks.