-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Creating the custom Voter #5279
Comments
Hey @colejarczyk! You're absolutely right, but it's done on purpose. The But, is this unclear in the docs? Are are you just looking very closely at things? :) Cheers! |
I found it by accident. I used this example to learn voters and thought that this maybe is not on purpose. If it is, then it's ok. It's very clear for me. I can only suggest to change method from getId to getUsername to keep with UserInterface, but this is just only a suggestion. |
Thanks @colejarczyk :). Actually, using Cheers! |
@weaverryan I'm not sure about this one. It is indeed true that |
@wouterj I disagree - we must assume that the |
I think we should add that kind of error handling. Indeed, if you configured everything in your application correctly, this will never happen. But we all know how difficult the Security component can be (especially for newcomers) and tracking the cause of the error may become hard without a proper error message. :) |
Maybe something like this can solve this problem? What do you think?
|
I think we have to throw an exception and just make things simple like |
agreed with this simple approach |
+1 - it adds clarity, which I like if (!$user instanceof User) {
throw new \LogicException('The user is somehow not our User class! This should never happen!');
} |
Btw, I think we have to be a bit carefull with "this should never happen". There are some people, @iltar for instance, who are using a different user object for the security than in their application. This adds a clear separation. |
Ok, then just take off the second sentence: if (!$user instanceof User) {
throw new \LogicException('The user is somehow not our User class!');
} |
I think it should respect the |
@iltar Why should someone make their business logic only rely on |
That's one of the reason I don't like using the Symfony Controller. Regarding voters, it all depends on your implementation I suppose. In my case I use Most of this logic is all abstracted but we still have to find a decent way of composing voters. Currently we have created around 40 |
PR at #5317! |
@weaverryan could you add a flag hasPR for easy lookups ? Thank you. |
This PR was merged into the 2.3 branch. Discussion ---------- Additional User check in voter class Finishes #5317 | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | 2.3+ | Fixed tickets | #5279 Commits ------- 9ad9daf Additional little check to show how we're assumign the User object is the User entity
This is a small thing. In Voter example $user object is an instance of Symfony\Component\Security\Core\User\UserInterface. Then in a switch statement there is a call to method getId() on $user, but there is no such method in UserInterface.
The text was updated successfully, but these errors were encountered: