vendor/roothirsch/shop-bundle/EventSubscriber/Api/EstimateDuplicateSubscriber.php line 31

Open in your IDE?
  1. <?php
  2. // api/src/EventSubscriber/BookMailSubscriber.php
  3. namespace Roothirsch\ShopBundle\EventSubscriber\Api;
  4. use ApiPlatform\Core\EventListener\EventPriorities;
  5. use Roothirsch\ShopBundle\Repository\EstimateRepository;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\HttpKernel\KernelEvents;
  8. final class EstimateDuplicateSubscriber implements EventSubscriberInterface
  9. {
  10. /**
  11. * @var \Roothirsch\ShopBundle\Repository\EstimateRepository
  12. */
  13. private $estimateRepository;
  14. public function __construct(EstimateRepository $estimateRepository)
  15. {
  16. $this->estimateRepository = $estimateRepository;
  17. }
  18. public static function getSubscribedEvents()
  19. {
  20. return [
  21. KernelEvents::VIEW => ['validate', EventPriorities::PRE_VALIDATE],
  22. ];
  23. }
  24. public function validate(\Symfony\Component\HttpKernel\Event\ViewEvent $event)
  25. {
  26. return;
  27. if ($event->getRequest()->attributes->get('_route') === 'api_estimates_duplicate_collection') {
  28. dump($event->getRequest()->attributes->get('id'), $this->estimateRepository->find($event->getRequest()->attributes->get('id')));
  29. /** @var \Roothirsch\ShopBundle\Entity\Estimate $estimate */
  30. $duplicate = clone $this->estimateRepository->find($event->getRequest()->attributes->get('id'));
  31. $duplicate->setCreated(time());
  32. $duplicate->setUpdated(time());
  33. $duplicate->setOrderedAt(null);
  34. $duplicate->setDeliveryDate(null);
  35. $duplicate->setId(null);
  36. $event->setControllerResult($duplicate);
  37. }
  38. }
  39. }