Пример #1
0
 private function validateEmail(User $entity, ViolationsList $violations)
 {
     $email = $entity->getEmail();
     if ($this->isEmpty($email)) {
         //Empty is okay, non-required field.
         return;
     }
     if (!EmailValidator::isValid($email)) {
         $violations->add('email', 'devture_user.validation.email.invalid');
         return;
     }
     //Make sure it's unique, so it can potentially be used as an alternative user identifier.
     try {
         $user = $this->repository->findByEmail($email);
         if ($user->getId() !== $entity->getId()) {
             $violations->add('email', 'devture_user.validation.email.in_use', array('%username%' => $user->getUsername()));
         }
     } catch (NotFound $e) {
     }
 }
Пример #2
0
 public static function validateTransferRequest(TransferRequest $entity)
 {
     $violations = new ViolationsList();
     if (!in_array($entity->getType(), TransferRequest::getKnownTypes())) {
         $violations->add('type', 'Invalid transfer request type: `%type%`.', array('%type%' => $entity->getType()));
     }
     if (!$entity->getSourceBankAccount() instanceof BankAccount) {
         $violations->add('sourceBankAccount', 'Source bank account cannot be blank.');
     } else {
         $violationsBankAccount = static::validateBankAccount($entity->getSourceBankAccount(), self::BANK_ACCOUNT_ROLE_SENDER);
         if (count($violationsBankAccount) > 0) {
             $violations->add('sourceBankAccount', 'Source bank account is invalid.');
         }
     }
     if (!$entity->getDate() instanceof \DateTime) {
         $violations->add('date', 'Date cannot be blank.');
     }
     if (count($entity->getTransactions()) == 0) {
         $violations->add('transactions', 'A transfer request needs to contain at least one transaction.');
     }
     foreach ($entity->getTransactions() as $transaction) {
         $violationsTransaction = static::validateMoneyTransferTransaction($transaction);
         if (count($violationsTransaction) > 0) {
             $violations->add('transactions', 'Transaction is invalid.');
         }
     }
     return $violations;
 }