-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[DX] Added CurrentUserProvider service #14407
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
ed12fe0
to
0532d49
Compare
return; | ||
} | ||
|
||
if (!is_object($user = $token->getUser())) { |
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.
-1 on this logic, even if user is not a string, it should return it. anon.
is a user too.
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.
yep a user is not necessarily represented by an object, it depend of implementation of token. (for example UsernamePasswordToken accept string representation of user to handle InMemoryUserProvider).
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 understand that some user representation might be a string. This PR is a refactor of the FrameworkBundle's Controller::getUser
. I've just put it to a service.
The CurrentUserProvider::getUser
function do have the same logic as in the FramworkBundle
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.
It's a mistake from FrameworkBundle so, this is why when we retrieve the current user from different way we obtains 'anon.' or null.
I know that the anonymous user is also considered as a user. But IMHO it's very rare that you bother about the anonymous user. If you do The intention is to make it easier in the 90% of the cases when you just want to fetch your user model for the current user without any extra check for tokens and if user is the string ´anon.`. |
Maybe you could make that intention a little more explicit by renaming the getUser method to getAuthenticatedUser? Or rename CurrentUserProvider to AuthenticatedUserProvider? That way it would be clearer that it will not return 'anon', only an authenticated user. |
You are absolutely correct @cvuorinen. If it is renamed to example |
Listening to your arguments and other friends in the community, I'm ready to drop this PR. It is bad design to use the user like this. One should inject the user in the method call as @iltar suggests. Thank you all for taking time to review this PR. |
I believe it would be nice to make it little easier to retrieve the current user. This provider will hide the complexity with the token and check if the
$token->getUser()
is an object or a string.