/** * Handle user unregistration * * @param UnregisterUser $command * @return void */ public function handle(UnregisterUser $command) { $id = $command->id; $user = $this->retrieveUser($id); $this->userRepository->remove($user); $this->events->fire([new UserWasUnregistered($user)]); }
/** * Handle role deletion * * @param DeleteRole $command * @return void */ public function handle(DeleteRole $command) { $id = $command->id; $role = $this->retrieveRole($id); $this->roleRepository->remove($role); $this->events->fire([new RoleWasDeleted($role)]); }
/** * Handle new user registration * * @param GrantRoleToUser $command * @return void */ public function handle(GrantRoleToUser $command) { $userId = $command->id; $roleId = $command->roleId; $user = $this->retrieveUser($userId); $role = $this->retrieveRole($roleId); $user->grantRole($role); $this->userRepository->save($user); $this->events->fire($user->releaseEvents()); }
/** * Handle role creation * * @param CreateNewRole $command * @return void */ public function handle(CreateNewRole $command) { $name = new FoundationDomainModels\Name($command->name); $description = new FoundationDomainModels\Description($command->description); $id = $this->roleRepository->nextIdentity(); $this->ensureNameIsUnique($name); $role = new AccountDomainModels\Role($id, $name, $description); $this->roleRepository->save($role); $this->events->fire([new RoleWasCreated($role)]); }
/** * Handle attach permission to role * * @param AttachPermissionToRole $command * @return void */ public function handle(AttachPermissionToRole $command) { $id = $command->id; $permissionId = $command->permissionId; $role = $this->retrieveRole($id); $permission = $this->retrievePermission($permissionId); $role->attachPermission($permission); $this->roleRepository->save($role); $this->events->fire($role->releaseEvents()); }
/** * Handle describe role * * @param DescribeRole $command * @return void */ public function handle(DescribeRole $command) { $name = new FoundationDomainModels\Name($command->name); $description = new FoundationDomainModels\Description($command->description); $id = new AccountDomainModels\RoleId($command->id); $this->ensureNameIsUnique($name, $id); $role = $this->retrieveRole($id->value()); $role->setName($name); $role->describe($description); $this->roleRepository->save($role); $this->events->fire($role->releaseEvents()); }
/** * Handle new user registration * * @param RegisterNewUser $command * @return void */ public function handle(RegisterNewUser $command) { $username = new AccountDomainModels\Username($command->username); $email = new FoundationDomainModels\Email($command->email); $description = new FoundationDomainModels\Description($command->description); $id = $this->userRepository->nextIdentity(); $roles = count($command->roles) ? $this->buildRoles($command->roles) : $this->roleRepository->getDefaultRoles(); $this->ensureUsernameIsUnique($username); $this->ensureEmailIsUnique($email); $user = new AccountDomainModels\User($id, $username, $email, $description, $roles); $this->userRepository->save($user); $this->events->fire([new UserWasRegistered($user)]); }
/** * Handle user unregistration * * @param DescribeUser $command * @return void */ public function handle(DescribeUser $command) { $id = new AccountDomainModels\UserId($command->id); $username = new AccountDomainModels\Username($command->username); $email = new FoundationDomainModels\Email($command->email); $description = new FoundationDomainModels\Description($command->description); $this->ensureUsernameIsUnique($username, $id); $this->ensureEmailIsUnique($email, $id); $user = $this->retrieveUser($id->value()); $user->setUsername($username); $user->setEmail($email); $user->describe($description); $this->userRepository->save($user); $this->events->fire($user->releaseEvents()); }