Checks if the given Role ID exists in the RolesStorage ArrayObject,
i.e. if the client is assigned to this role.

@param  int|RoleInterface $id RoleInterface instance or role ID
@return bool
496854
public function contains( $id )
    {
        $iterator = $this->getIterator();

        $role_id = ($id instanceOf RoleInterface) ? $id->getId() : $id;

        while ($iterator->valid()) {
            if ($iterator->current() == $role_id) {
                return true;
            }
            $iterator->next();
        }

        return false;
    }
1069175
public function removeRole($id, $role)
    {
        $user = $this->getUser($id);

        if (empty($user) || empty($role)) {
            return false;
        }

        // Remove the role from the $user['roles'] array.
        $user['roles'] = array_diff($user['roles'], [(string) $role]);

        return $this->saveUser($user);
    }
915975
public function hasRoleById(int $roleId): bool
    {
        if (isset($this->roles[$roleId])) {
            return true;
        }

        return false;
    }
1240187
public function isPermissionAssigned($permissionId, $roleIds)
    {
        $qb = $this->createQueryBuilder('rolePermission');

        $result = $qb
            ->select('rolePermission.id')
            ->where(
                $qb->expr()->andX(
                    $qb->expr()->eq('rolePermission.permissionId', $permissionId),
                    $qb->expr()->in('rolePermission.roleId', $roleIds)
                )
            )
            ->setMaxResults(1)
            ->getQuery()
            ->getArrayResult();

        return count($result) > 0;
    }
435342
public function assignRole($roleId = null)
    {
        $roles = $this->roles;

        if (! $roles->contains($roleId)) {
            return $this->roles()->attach($roleId);
        }

        return false;
    }
895177
private function collectPermissions(RoleInterface $role)
    {
        if (method_exists($role, 'getPermissions')) {
            $permissions = $role->getPermissions();
        } else {
            // Gather the permissions for the given role. We have to use reflection as
            // the RoleInterface does not have "getPermissions" method
            $reflectionProperty = new ReflectionProperty($role, 'permissions');
            $reflectionProperty->setAccessible(true);

            $permissions = $reflectionProperty->getValue($role);
        }

        if ($permissions instanceof Traversable) {
            $permissions = iterator_to_array($permissions);
        }

        array_walk($permissions, function (&$permission) {
            $permission = (string) $permission;
        });

        $this->collectedPermissions[$role->getName()] = array_values($permissions);
    }
826481
protected function hasService($id) {
		$method = sprintf($this->methodNameTemplate, lcfirst($id));
		
		return method_exists($this, $method);
	}
1339795
public function hasRole($role)
    {
        if (is_array($role)) {
            return in_array($this->attributes['role'], $role);
        }

        return $this->attributes['role'] == $role;
    }
57282
protected function hasRole($role) {
		if(!$this->container->has('security.authorization_checker')) {
			throw new \LogicException('The SecurityBundle is not registered in your application.');
		}
		return false !== $this->get('security.authorization_checker')->isGranted($role);
	}
220250
final public function hasRequiredRole(UserInterface $user = null, array $roles = [])
    {
        if ($user != null) {
            // Check if user's roles matches required roles
            $userRoles = $user->getRoles();

            foreach ($userRoles as $role) {
                if (\in_array($role, $roles)) {
                    return true;
                }
            }
        }

        return false;
    }
1191852
public function addRole(RoleInterface $role)
    {
        $this->roles->add($role);

        if ($role->hasUser($this) === false)
            $role->addUser($this);

        return $this;
    }
123458
public function hasRole($role)
    {
        $roles = array_column($this->roles->toArray(), 'name');
        return array_search($role, $roles) > -1;
    }
437307
public function assignRole($role)
    {
        return $this->mapArray($role, function ($role) {

            $roleId = $this->parseRoleId($role);

            if ( ! $this->roles->keyBy('id')->has($roleId) ) {
                $this->roles()->attach($roleId);

                return $role;
            }

            return false;
        });
    }
1069668
public function has($id)
    {
        if (isset($this->resolved[$id])) {
            return true;
        }

        if (isset($this->definitions[$id])) {
            return true;
        }

        // How can this be moved to the ReflectionResolver?
        if (class_exists($id)) {
            return true;
        }

        return false;
    }
875119
public function delete(string $id = null)
    {
        $this->request->allowMethod(['post', 'delete']);
        $role = $this->Roles->get($id);
        if ($this->Roles->delete($role)) {
            $this->Flash->success((string)__('The role has been deleted.'));
        } else {
            $this->Flash->error((string)__('The role could not be deleted. Please, try again.'));
        }

        return $this->redirect(['action' => 'index']);
    }
102635
public function grantAccess($roleOrPermission, UserInterface $user = null)
    {
        $user = $user ? : $this->currentUser();

        if (is_array($roleOrPermission) && $this->grantAccessByRoles($roleOrPermission, $user)) {
            return true;
        } else if (is_array($roleOrPermission) && $this->grantAccessByPermissions($roleOrPermission, $user)) {
            return true;
        } else if ($this->grantAccessByRole($roleOrPermission, $user)) {
            return true;
        } else if ($this->grantAccessByPermission($roleOrPermission, $user)) {
            return true;
        }

        return false;
    }
226340
public function delete($id)
    {
        try {
            $this->roleRepositoryInterface->delete($id);
        } catch (RolesException $e) {
            Flash::error($e->getMessage());

            return redirect()->route('roles.index');
        }

        Flash::success(trans('dashboard::dashboard.flash.role.delete.success'));

        return redirect()->route('roles.index');
    }