private function generateNames(Client $client) { $firstNames = ['Paul', 'Dave', 'Mark', 'Jerome', 'Eleonor', 'Pauline', 'Daniel', 'Vincent']; $lastNames = ['Gauthier', 'Smith', 'Dupont', 'Martin', 'Richard', 'Lefevre', 'Lambert', 'Sanchez', 'Perrin', 'Chevalier']; $firstName = $firstNames[array_rand($firstNames, 1)]; $lastName = $lastNames[array_rand($lastNames, 1)]; $client->setFirstName($firstName); $client->setLastName($lastName); return $client; }
/** * This method will update a client * * @ApiDoc( * section="Clients", * resource=true, * description="This method will update a client", * statusCodes={ * 200="Returned when successful", * 403="Returned when the user is not authorized", * 404={ * "Returned when the posts are not found" * } * } * ) * @Extra\Route("/{id}") * @Extra\Method({"PUT"}) * @ParamConverter("client", class="JdhmApi\Entity\Client") * @Rest\View() */ public function updateClientAction(Client $client, Request $request) { $em = $this->get('doctrine')->getManager(); $content = json_decode($request->getContent(), true); if (!$content) { throw new HttpException("No json data in body", 405); } $client->setFirstName($content['firstName']); $client->setLastName($content['lastName']); $client->setEmail($content['email']); if (array_key_exists('dateOfBirth', $content) && !empty($content['dateOfBirth'])) { $date = \DateTime::createFromFormat('d/m/Y', $content['dateOfBirth']); $client->setDateOfBirth($date); } $em->persist($client); $em->flush(); return ['data' => $client]; }