src/Component/AuthManager.php
public function assign(Role $role, $userId)
    {
        $userRole = new UserRole();

        $userRole->setUserId($userId);
        $userRole->setRole($role);

        try {
            $this->saveEntity($userRole);
        } catch (UniqueConstraintViolationException $e) {
            throw new NotUniqueException('Role ' . $role->getName() . 'is already assigned to user with identifier ' . $userId);
        }
    }
public function assign(Role $role, $userId)
    {
        $userRole = new UserRole();

        $userRole->setUserId($userId);
        $userRole->setRole($role);

        try {
            $this->saveEntity($userRole);
        } catch (UniqueConstraintViolationException $e) {
            throw new NotUniqueException('Role ' . $role->getName() . 'is already assigned to user with identifier ' . $userId);
        }
    }
public function assign ( Role $ role , $ userId ) { $ userRole = new UserRole ( ) ; $ userRole -> setUserId ( $ userId ) ; $ userRole -> setRole ( $ role ) ; try { $ this -> saveEntity ( $ userRole ) ; } catch ( UniqueConstraintViolationException $ e ) { throw new NotUniqueException ( 'Role ' . $ role -> getName ( ) . 'is already assigned to user with identifier ' . $ userId ) ; } }
Assign role to user
@param Role $role
@param integer $userId
@throws NotUniqueException
@throws DatabaseException
Assign role to user