本文整理汇总了PHP中Symfony\Component\Security\Core\Authentication\Token\TokenInterface::setRoles方法的典型用法代码示例。如果您正苦于以下问题:PHP TokenInterface::setRoles方法的具体用法?PHP TokenInterface::setRoles怎么用?PHP TokenInterface::setRoles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Security\Core\Authentication\Token\TokenInterface
的用法示例。
在下文中一共展示了TokenInterface::setRoles方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: refreshUser
/**
* Refreshes the user by reloading it from the user provider
*
* @param TokenInterface $token
*
* @return TokenInterface|null
*/
protected function refreshUser(TokenInterface $token)
{
$user = $token->getUser();
if (!$user instanceof AccountInterface) {
return $token;
}
if (null !== $this->logger) {
$this->logger->debug(sprintf('Reloading user from user provider.'));
}
foreach ($this->userProviders as $provider) {
try {
$cUser = $provider->loadUserByAccount($user);
$token->setRoles($cUser->getRoles());
$token->setUser($cUser);
if (false === $cUser->equals($user)) {
$token->setAuthenticated(false);
}
if (null !== $this->logger) {
$this->logger->debug(sprintf('Username "%s" was reloaded from user provider.', $user));
}
return $token;
} catch (UnsupportedAccountException $unsupported) {
// let's try the next user provider
} catch (UsernameNotFoundException $notFound) {
if (null !== $this->logger) {
$this->logger->debug(sprintf('Username "%s" could not be found.', $user));
}
return null;
}
}
throw new \RuntimeException(sprintf('There is no user provider for user "%s".', get_class($user)));
}