Пример #1
0
 /**
  * @param UserRegisterCommand $command
  *
  * @return bool
  */
 public function validate(UserRegisterCommand $command)
 {
     /**
      * @var Validator $validator
      */
     $validator = $this->validator->make($command->toArray(), $this->rules);
     if ($validator->fails()) {
         throw new ValidationFailedException($validator->errors());
     }
     return true;
 }
Пример #2
0
 /**
  * Handle the command
  *
  * @param UserRegisterCommand $command
  * @return UserInterface
  * 
  * @throws UserNotStoredException
  */
 public function handle($command)
 {
     $newUser = $this->userRepository->create();
     $newUser->setIdentifier($command->getFieldValue($this->identifierFieldName));
     $newUser->setEmail(strtolower($command->email));
     $newUser->setPassword($command->password);
     foreach ($this->extraFields as $extraField) {
         $fieldName = $extraField['name'];
         $newUser->setExtra($fieldName, $command->getExtraFieldValue($fieldName));
     }
     $this->raise(new UserWasCreated($newUser));
     $this->dispatchEventsFor($this);
     return $newUser;
 }