src/EventSubscriber/VehicleTypeSubscriber.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use Exception;
  4. use App\Model\Vehicle;
  5. use App\Service\FileService;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\Form\Event\PostSubmitEvent;
  8. use Symfony\Component\Form\FormEvents;
  9. class VehicleTypeSubscriber implements EventSubscriberInterface
  10. {
  11.     private FileService $fileService;
  12.     public function __construct(FileService $fileService)
  13.     {
  14.         $this->fileService $fileService;
  15.     }
  16.     /**
  17.      * @throws Exception
  18.      */
  19.     public function onPostSubmit(PostSubmitEvent $event): void
  20.     {
  21.         /** @var Vehicle $client */
  22.         $vehicle $event->getData();
  23.         $form $event->getForm();
  24.         if (!$vehicle instanceof Vehicle) {
  25.             return;
  26.         }
  27.         $registrationFiles $form->get('registrationFiles')->getData();
  28. //        dd(base64_encode(file_get_contents($registrationFiles[0])));
  29. //        $this->fileService->uploadMultipleFiles($registrationFiles, $vehicle, 'registrationFiles');
  30. //
  31. //        $conversionFiles = $form->get('conversionFiles')->getData();
  32. //
  33. //        $this->fileService->uploadMultipleFiles($conversionFiles, $vehicle, 'conversionFiles');
  34. //
  35. //        $event->setData($vehicle);
  36.     }
  37.     public static function getSubscribedEvents(): array
  38.     {
  39.         return [
  40.             FormEvents::POST_SUBMIT => 'onPostSubmit',
  41.         ];
  42.     }
  43. }