Esempio n. 1
0
 /**
  * Handle the command
  *
  * @param UserStoreCommand $command
  * @return mixed
  */
 public function handle($command)
 {
     $newUser = $command->user;
     if (!$this->userRepository->save($newUser)) {
         throw new UserNotStoredException($newUser);
     }
     $this->raise(new UserWasRegistered($newUser));
     $this->dispatchEventsFor($this);
 }
Esempio n. 2
0
 /**
  * Handle the command
  *
  * @param UserEditCommand $command
  * @return mixed
  */
 public function handle($command)
 {
     $user = $command->user;
     $changes = [];
     if ($command->emailWasChanged()) {
         $user->setEmail($command->email);
         $changes['email'] = 'Changed';
     }
     if ($command->passwordWasChanged()) {
         $changes['password'] = '******';
         $user->setPassword($command->password);
     }
     foreach ($command->extraFields as $field => $value) {
         if ($command->extraFieldWasChanged($field)) {
             $user->setExtra($field, $value);
         }
     }
     if (!$this->userRepository->save($user)) {
         throw new UserNotStoredException($user);
     }
     return $changes;
 }