Create role.

@param string $roleName

@return \Artesaos\Defender\Role
778366
protected function createRole($roleName)
    {
        // No need to check is_null($role) as create() throwsException
        $role = $this->roleRepository->create($roleName);

        $this->info('Role created successfully');

        return $role;
    }
878913
public static function fromAccount($role)
    {
        return $role instanceof RoleInterface
            ? new self(ClassUtils::getClass($role), $role->getName())
            : new self('role', $role);
    }
260335
public function createRole(RoleAssignment $roleAssignment): UIValue\User\Role
    {
        return new UIValue\User\Role($roleAssignment);
    }
4206
public function addRoleForUser($userId, $roleName)
    {
        $roleIdExpression = new Expression(
            '(SELECT `id` from `user_roles` WHERE `name` = ?)',
            $roleName
        );

        $query = $this->getSqlObject()
            ->insert()
            ->values([
                'user_id' => $userId,
                'role_id' => $roleIdExpression,
            ]);

        $this->execute($query);
    }
68019
public function ensureRoleExists($name)
    {
        try {
            $role = $this->roleService->loadRoleByIdentifier($name);
        } catch (ApiExceptions\NotFoundException $e) {
            $roleCreateStruct = $this->roleService->newRoleCreateStruct($name);
            $roleDraft = $this->roleService->createRole($roleCreateStruct);
            $this->roleService->publishRoleDraft($roleDraft);
            $role = $this->roleService->loadRole($roleDraft->id);
        }

        return $role;
    }
798920
def create_role(self, role_name, role_type, host_id):
    
    return roles.create_role(self._get_resource_root(), self.name, role_type,
        role_name, host_id, self._get_cluster_name())
1159261
public function addRole($roleName)
    {
        if (empty($roleName)) {
            throw new PropertyNotValid('Role name cannot be empty.');
        }

        if ($this->hasRole($roleName)) {
            return;
        }

        $this->roles[] = $roleName;
    }
1013405
private function createDeleteForm(Role $role)
    {
        return $this->createFormBuilder()
            ->setAction($this->generateUrl('core_role_delete', array('id' => $role->getId())))
            ->setMethod('DELETE')
            ->getForm()
        ;
    }
934245
protected function findRole($roleName)
    {
        if (($role = $this->_authManager->getRole($roleName)) !== null) {
            return $role;
        }

        throw new Exception(Yii::t('yii2mod.user', 'The role "{roleName}" is not found.', [
            'roleName' => $roleName,
        ]));
    }
276688
public function removeRole(string $role): PermissionManager
    {
        if (!$this->hasRole($role)) {
            throw new RoleException("Undefined role '{$role}'");
        }

        unset($this->permissions[$role]);

        return $this;
    }
447673
private function createRole(ObjectManager $manager, $name)
    {
        $role = new Role($name);
        $manager->persist($role);

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

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

        return false;
    }
394250
public function getRoleAssigments($roleName) {
        $query = (new Query)->from($this->assignmentTable)
            ->where(['item_name' => $roleName]);

        $assignments = [];
        foreach ($query->all($this->db) as $row) {
            $assignments[$row['user_id']] = new Assignment([
                'userId' => $row['user_id'],
                'roleName' => $row['item_name'],
                'createdAt' => $row['created_at'],
            ]);
        }

        return $assignments;
    }
395801
public function createRole(Role $role)
    {
        try {
            return $this->innerGateway->createRole($role);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
1228736
public static function create($parsed)
    {
        $role = new self();
        $roleName = Utilities::tryGetValue(
            $parsed,
            Resources::XTAG_ROLE_NAME
        );
        $osVersion = Utilities::tryGetValue(
            $parsed,
            Resources::XTAG_OS_VERSION
        );

        $role->setOsVersion($osVersion);
        $role->setRoleName($roleName);

        return $role;
    }
1294241
static function create( $roleName, $version = 0 )
    {
        $row = array( 'id' => null,
                      'name' => $roleName,
                      'version' => 0 );
        $role = new eZRole( $row );
        return $role;
    }
741457
protected static function createGeneral()
	{
	    $roleModel = new \erdiko\users\models\Role;
        $roleGeneral = $roleModel->findByName('general');
        if (empty($roleGeneral)) {
            throw new \Exception('Role general not found.');
        }

		$entity = new entity();
		$entity->setId( 0 );
		$entity->setRole( $roleGeneral->getId() );
		$entity->setName( 'user' );
		$entity->setEmail( 'user' );
		return $entity;
	}