本文整理汇总了PHP中Sylius\Component\User\Model\UserInterface::hasRole方法的典型用法代码示例。如果您正苦于以下问题:PHP UserInterface::hasRole方法的具体用法?PHP UserInterface::hasRole怎么用?PHP UserInterface::hasRole使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sylius\Component\User\Model\UserInterface
的用法示例。
在下文中一共展示了UserInterface::hasRole方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: executeRoleCommand
/**
* {@inheritdoc}
*/
protected function executeRoleCommand(OutputInterface $output, UserInterface $user, array $securityRoles)
{
$error = false;
foreach ($securityRoles as $securityRole) {
if (!$user->hasRole($securityRole)) {
$output->writeln(sprintf('<error>User "%s" didn\'t have "%s" Security role.</error>', (string) $user, $securityRole));
$error = true;
continue;
}
$user->removeRole($securityRole);
$output->writeln(sprintf('Security role <comment>%s</comment> has been removed from user <comment>%s</comment>', $securityRole, (string) $user));
}
if (!$error) {
$this->getEntityManager()->flush();
}
}
示例2: userCanAccessWishlist
/**
* Check if a wishlist is publicly available, or the
* user has special privileges to access it.
*
* @param $user
* @param $wishlist
* @return bool
*/
protected function userCanAccessWishlist(UserInterface $user = null, WishlistInterface $wishlist)
{
if ($wishlist->isPublic()) {
return true;
}
if ($user) {
if ($user->hasRole('ROLE_ADMINISTRATION_ACCESS') || $user->getCustomer() && $user->getCustomer()->getId() == $wishlist->getCustomer()->getId()) {
return true;
}
}
return false;
}