toArray(); $requestDto = new RegisterRequest($content['email'] ?? '', $content['password'] ?? ''); $violations = $this->validator->validate($requestDto); if (\count($violations) > 0) { $errors = []; foreach ($violations as $violation) { $errors[$violation->getPropertyPath()][] = $violation->getMessage(); } return $this->json(['errors' => $errors], 422); } $user = new User(); $user->setEmail($requestDto->email); $user->setPassword($this->passwordHasher->hashPassword($user, $requestDto->password)); $this->entityManager->persist($user); $this->entityManager->flush(); return $this->json([ 'id' => (string) $user->getId(), 'email' => $user->getEmail(), ], 201); } }