/** * Adds user data to storage */ public function addUser() { $user = new User(); $user->setId('999999999')->setName('john')->setEmail('*****@*****.**')->setPassword('test'); $this->userService->addUser($user); $this->users[] = $user; }
/** * Processes the form. * * @param User $user * @param array $parameters * @param String $method * * @return User Entity * * @throws ElasticaClient\UserBundle\Exception\InvalidFormException */ private function processForm(User $user, $parameters, $method = 'PUT') { $form = $this->formFactory->create(new UserType(), $user, array('method' => $method)); $form->submit($parameters); if ($form->isValid()) { $user = $form->getData(); if ($userResponse = $this->getByEmail($user->getEmail())) { if ($method == 'POST') { throw new UserExistException('This User Exist', 'user-exist'); } else { if ($user->getId() == $userResponse->getId()) { $this->userService->deleteUser($user->getId()); $this->userService->addUser($user); return $user; } else { throw new UserExistException('This User Exist', 'user-exist'); } } } else { $userId = $this->userService->addUser($user); $user->setId($userId); return $user; } } throw new InvalidFormException('Invalid submitted data', $form); }