예제 #1
0
 /**
  * @param User|int $recipient
  */
 private function setRecipient($recipient)
 {
     if ($recipient instanceof User and !$recipient->isDetached()) {
         $this->assignEntityToProperty($recipient, 'recipient');
     } else {
         if (Validators::is($recipient, 'numericint')) {
             $this->row->recipient = $recipient;
             $this->row->cleanReferencedRowsCache('user', 'recipient');
         } else {
             throw new InvalidArgumentException('Argument $recipient can by only instance of App\\Entities\\User or
              integer number.');
         }
     }
 }
예제 #2
0
 /**
  * @param \App\Model\Entities\User|int $user
  * @return int
  */
 protected function getUserID($user)
 {
     $id = null;
     if ($user instanceof User and !$user->isDetached()) {
         $id = $user->userID;
     } else {
         if (Validators::is($user, 'numericint')) {
             $id = $user;
         } else {
             throw new InvalidArgumentException('Argument $user must be instance of ' . User::class . '
              or integer number.');
         }
     }
     return $id;
 }
예제 #3
0
 /**
  * @param User $user
  * @param Invitation $invitation
  * @return void
  * @throws Runtime\DuplicateUsernameException
  * @throws Runtime\DuplicateEmailException
  * @throws Runtime\InvitationNotFoundException
  * @throws Runtime\InvitationExpiredException
  * @throws Runtime\InvitationTokenMatchException
  * @throws \DibiException
  */
 public function registerNewUser(User $user, Invitation $invitation)
 {
     if (!$user->isDetached()) {
         throw new InvalidArgumentException('Only detached instances of Entity ' . User::class . ' can pass.');
     }
     $this->checkInvitation($user->email, $invitation->token);
     try {
         $this->transaction->begin();
         $this->userRepository->persist($user);
         $this->removeInvitation($invitation);
         $this->transaction->commit();
     } catch (\DibiException $e) {
         if ($e->getCode() == 1062) {
             try {
                 $this->userRepository->checkUsername($user->username);
             } catch (Runtime\UserAlreadyExistsException $usernameException) {
                 $this->transaction->rollback();
                 throw new Runtime\DuplicateUsernameException();
             }
             try {
                 $this->userRepository->checkEmail($user->email);
             } catch (Runtime\UserAlreadyExistsException $emailException) {
                 $this->transaction->rollback();
                 throw new Runtime\DuplicateEmailException();
             }
         }
         $this->transaction->rollback();
         Debugger::log($e, Debugger::ERROR);
         throw $e;
     }
 }