Validate role

@param mixed $role

@return bool
431489
public function validateDefaultRole($role)
    {
        if (empty($role)) {
            $this->addError('role', 'Role cannot be empty');
            return false;
        }

        if (!$role instanceof Role) {
            $this->addError('role', 'Role must be a Role entity');
            return false;
        }

        return true;
    }
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;
        });
    }
1356513
protected function validateRoleUser()
    {
        $field = 'role_id';
        $value = $this->getSubmitted($field);

        if (empty($value)) {
            return null;
        }

        $label = $this->translation->text('Role');

        if (!is_numeric($value)) {
            $this->setErrorNumeric($field, $label);
            return false;
        }

        $role = $this->role->get($value);

        if (empty($role)) {
            $this->setErrorUnavailable($field, $label);
            return false;
        }

        return true;
    }
241253
public function hasRole($role)
    {
        if ($this->instance instanceof \Phavour\Session\Storage) {
            $roles = $this->instance->get('roles');
            if (is_array($roles) && in_array($role, $roles)) {
                return true;
            }
        }

        return false;
    }
1281147
public function addRole($role)
    {
        $role = strtoupper($role);
        if (static::ROLE_DEFAULT === $role) {
            return $this;
        }

        if (!$this->hasRole($role)) {
            $this->roles[] = $role;
        }

        return $this;
    }
444696
protected function validateUserRole()
    {
        $id = $this->getUpdatingId();

        if ($id === false) {
            return null;
        }

        $data = $this->role->get($id);

        if (empty($data)) {
            $this->setErrorUnavailable('update', $this->translation->text('Role'));
            return false;
        }

        $this->setUpdating($data);
        return true;
    }
582569
public function hasOneRole($role)
    {
        foreach ($this->getArrayFrom($role) as $role) {
            if ($this->checkRole($role)) {
                return true;
            }
        }

        return false;
    }
938098
public function hasRole($role)
    {
        foreach ($this->roles as $roleObj) {
            if($role == $roleObj->getRole()){
                return true;
            }
        }
        return false;
    }
1124277
private function validateRole($role, $roles, $checkExistence = true)
    {
        if (empty($roles)) {
            return null;
        }

        $roleExists = array_key_exists($role, $roles);
        $condition =  $checkExistence ? !$roleExists : $roleExists;
        if ($condition) {
            $errorMessage = $checkExistence ? "Role %s doesn't exist" : 'Role %s already exists';
            throw new \InvalidArgumentException(sprintf($errorMessage, $role));
        }

        return $role;
    }
1072996
public static function hasRole($role)
    {
        if (!isset($_SESSION['user'])) {
            return false;
        };
        if (!isset($_SESSION['ACL_ROLES'])) {
            return false;
        };
        return in_array($role, $_SESSION['ACL_ROLES']);
    }
237406
public function hasRoles($roles)
    {
        $roles = is_array($roles) ? $roles : func_get_args();

        foreach ($roles as $role) {
            if ($this->hasRole($role)) {
                return true;
            }
        }

        return false;
    }
172376
public function removeRole($role)
    {
        $key = array_search(strtoupper($role), $this->roles, true);
        if (false !== $key) {
            /** @var string $key */
            unset($this->roles[$key]);
            $this->roles = array_values($this->roles);
        }

        return $this;
    }
651638
public function try_to_login_as_the_role( $role )
	{
		$role = $this->replace_variables( $role );

		$params = $this->get_params();

		if ( empty( $params['roles'][ $role ] ) ) {
			throw new \InvalidArgumentException( sprintf(
				"Role '%s' is not defined in the `behat.yml`", $role
			) );
		} else {
			$result = $this->login(
				$params['roles'][ $role ]['username'],
				$params['roles'][ $role ]['password']
			);
		}
	}
388219
public function hasRole($role = "general")
	{
        $roleModel = new \erdiko\users\models\Role;
        $roleEntity = $roleModel->findByName($role);
        if (empty($roleEntity)) {
            throw  new \Exception("Error, role {$role} not found.");
        }
        $result = $this->_user->getRole() == $roleEntity->getId();

		return $result;
	}
357217
public function hasRoles($roles): bool
    {
        $userRoles = $this->getRoles()->all();

        // We should ensure that all given roles match the current user,
        // consider it as a AND condition instead of OR.
        foreach ((array) $roles as $role) {
            if (! \in_array($role, $userRoles)) {
                return false;
            }
        }

        return true;
    }
1309949
public function is($roles)
	{
		if (!$this->user())
		{
			return false;
		}

		$userRoles = $this->getUser()->roles;

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

		return false;
	}
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);
	}