EasyCorp\Bundle\EasySecurityBundle\Security\Security::hasRole PHP Метод

hasRole() публичный Метод

Returns true if the current application user (or the optionally given user) has the given role. It takes into account the full role hierarchy.
public hasRole ( $role, null $user = null ) : boolean
$role
$user null
Результат boolean
    public function hasRole($role, $user = null)
    {
        $roleName = $role instanceof Role ? $role->getRole() : $role;
        $user = $user ?: $this->getUser();
        if (!$user instanceof UserInterface) {
            return false;
        }
        if (null === $this->roleHierarchy) {
            return in_array($roleName, $user->getRoles(), true);
        }
        $userRoles = $this->roleHierarchy->getReachableRoles($this->getUserRolesAsObjects($user));
        foreach ($userRoles as $userRole) {
            if ($roleName === $userRole->getRole()) {
                return true;
            }
        }
        return false;
    }