/** * @param array $data * @return UserModel * @throws InvalidFormException * @throws UserAlreadyExistsException * @throws \Exception */ public function validate(array $data) { $form = new SignUp(); $entity = new UserModel(); $form->bind($data, $entity); if (!$form->isValid($data)) { throw new InvalidFormException($form); } $email = $data['email']; $usersCount = UserModel::count([['email' => $email]]); if ($usersCount > 0) { throw new UserAlreadyExistsException(); } if ($data['password'] !== $data['password']) { throw new \Exception('Passwords do not match'); } unset($entity->repassword); return $entity; }