Я использую оператор из приложения Symfony2 в Symfony4:
$securityContext = $this->container->get('security.token_storage');
if ($securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED') ){
. . .
}
Я всегда получаю ошибку:
Attempted to call an undefined method named "isGranted" of class "Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage
что мне не хватает?
Привет, Стефано, не могли бы наши ответы помочь тебе решить проблему?






Symfony gives you several ways to enforce authorization, including […] using
isGrantedon thesecurity.authorization_checkerservice directly.
Вы должны звонить isGranted в службу security.authorization_checker, а не в security.token_storage.
для SF4, согласно документам:
public function hello($name)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_REMEMBERED');
// ...
}
Вы должны использовать сервис security.authorization_checker. И код выше такой же, как:
public function hello($name, AuthorizationCheckerInterface $authChecker)
{
if (false === $authChecker->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException('Unable to access this page!');
}
// ...
}
проверить документы здесь https://symfony.com/doc/4.0/security.html#securing-controllers-and-other-code
вы уже видели этот stackoverflow.com/a/36533186/2270041?