-
-
Notifications
You must be signed in to change notification settings - Fork 52
Fixed Symfony 4.3 deprecated messages #50
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
* @param TokenInterface $token | ||
* | ||
* @return array | ||
*/ |
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'd suggest removing the full dobclock here, it doesn't provide enough value.
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.
@nicolas-grekas Done.
Thank you @XWB. |
This PR was merged into the 3.0-dev branch. Discussion ---------- Fixed Symfony 4.3 deprecated messages This should resolve the following errors: > The getReachableRoles() method of the RoleHierarchyInterface is deprecated > The getRoles() method of the TokenInterface is deprecated Commits ------- d1a4c3f Fixed Symfony 4.3 deprecated messages
} | ||
} else { | ||
// Symfony < 4.3 BC layer | ||
foreach ($this->roleHierarchy->getReachableRoles($roles) as $role) { |
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.
https://github.com/symfony/security-core/blob/4.2/Role/RoleHierarchy.php#L41
getReachableRoles expected array of RoleInterface. Array of string given.
I think $roles = $this->getRoleNames($token);
need move into condition if (method_exists($this->roleHierarchy, 'getReachableRoleNames')) {
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.
Can you please send a PR if there's something to fix?
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.
Thanks for the quick reply. Yes, of course, I’m doing it right now...
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.
@Andrej-in-ua That might trigger another deprecation warning. I think changing the getRoleNames
method should do the trick.
You can try to change this:
private function getRoleNames(TokenInterface $token): array
{
if (method_exists($token, 'getRoleNames')) {
return $token->getRoleNames();
}
// Symfony < 4.3 BC layer
return array_map(function (Role $role) {
return $role->getRole();
}, $token->getRoles());
}
Into this:
private function getRoleNames(TokenInterface $token): array
{
if (method_exists($token, 'getRoleNames')) {
return $token->getRoleNames();
}
return $token->getRoles();
}
?
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.
@XWB In this case, we will rely on the fact that if there is a method getRoleNames
exists, then there will definitely exists getReachableRoleNames
. I do not know all the nuances so well. But if you confirm that it is ok, then I do PR.
At least right after I deal with the tests :/
In my project both solution worked.
This PR was merged into the 3.0-dev branch. Discussion ---------- Fixed Symfony 4.3 wrong role variable type This should fix work in symfony < 4.3 Original error from logs symfony 3.4 application: ``` Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalThrowableError: "Call to a member function getRole() on string" at vendor/symfony/symfony/src/Symfony/Component/Security/Core/Role/RoleHierarchy.php line 41 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Call to a member function getRole() on string at vendor/symfony/symfony/src/Symfony/Component/Security/Core/Role/RoleHierarchy.php:41 ``` Found in #50 (comment) Commits ------- 489dc66 Fixed Symfony 4.3 wrong role variable type
This should resolve the following errors: