Fixed Symfony 4.3 deprecated messages#50
Conversation
| * @param TokenInterface $token | ||
| * | ||
| * @return array | ||
| */ |
There was a problem hiding this comment.
I'd suggest removing the full dobclock here, it doesn't provide enough value.
|
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.
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.
Can you please send a PR if there's something to fix?
There was a problem hiding this comment.
Thanks for the quick reply. Yes, of course, I’m doing it right now...
There was a problem hiding this comment.
@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.
@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: