src/EventSubscriber/ImagePayloadMapperSubscriber.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Payload\ImagePayload;
  4. use Artyum\RequestDtoMapperBundle\Event\PreDtoValidationEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class ImagePayloadMapperSubscriber implements EventSubscriberInterface
  7. {
  8. public function onPreDtoValidation(PreDtoValidationEvent $event): void
  9. {
  10. $payload = $event->getDto();
  11. if (($payload instanceof ImagePayload) === false) {
  12. return;
  13. }
  14. // sets the uploaded image to the DTO (cannot use the Denormalizer for that)
  15. $payload->file = $event->getRequest()->files->get('file');
  16. }
  17. public static function getSubscribedEvents(): array
  18. {
  19. return [
  20. PreDtoValidationEvent::class => 'onPreDtoValidation',
  21. ];
  22. }
  23. }