Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * @Route("", name="", methods={"POST"})
  5. * @Permissions(adminPermissions=true)
  6. *
  7. * @param Task $task
  8. * @param Request $request
  9. * @param Publish\Handler $handler
  10. * @return JsonResponse
  11. * @throws \Symfony\Component\Serializer\Exception\ExceptionInterface
  12. */
  13. public function publish(Task $task, Request $request, Publish\Handler $handler): JsonResponse
  14. {
  15. /** @var Publish\Command $command */
  16. $command = $this->denormalizer->denormalize(
  17. $request->request->all(),
  18. Publish\Command::class,
  19. 'array',
  20. [
  21. 'ignored_attributes' => ['user', 'task']
  22. ]
  23. );
  24.  
  25. $command->user = $this->getUser();
  26. $command->task = $task;
  27.  
  28. $violations = $this->validator->validate($command);
  29. $errors = [];
  30.  
  31. if (\count($violations) > 0) {
  32. /** @var ConstraintViolation $violation */
  33. foreach ($violations as $violation) {
  34. $errors[] = $violation->getMessage();
  35. }
  36.  
  37. return $this->json(['error' => $errors], 200);
  38. }
  39.  
  40. try {
  41. $handler->handle($command);
  42. return $this->json(['success' => 1], 200);
  43. } catch (\DomainException $e) {
  44. $this->logger->warning($e->getMessage());
  45. return $this->json(['success' => 0], 500);
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement