<?php
namespace App\EventSubscriber;
use App\Payload\FilePayload;
use Artyum\RequestDtoMapperBundle\Event\PreDtoValidationEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class FilePayloadMapperSubscriber implements EventSubscriberInterface
{
public function onPreDtoValidation(PreDtoValidationEvent $event): void
{
$payload = $event->getDto();
if (($payload instanceof FilePayload) === false) {
return;
}
// sets the uploaded image to the DTO (cannot use the Denormalizer for that)
$payload->file = $event->getRequest()->files->get('file');
}
public static function getSubscribedEvents(): array
{
return [
PreDtoValidationEvent::class => 'onPreDtoValidation',
];
}
}