src/Infrastructure/File/EventSubscriber/FileSubscriber.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Infrastructure\File\EventSubscriber;
  3. use App\Infrastructure\File\Event\FileDeleteEvent;
  4. use App\Infrastructure\File\Event\FileUploadEvent;
  5. use App\Infrastructure\File\Service\FileUploader;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class FileSubscriber implements EventSubscriberInterface
  8. {
  9.     public function __construct(
  10.         private readonly FileUploader $fileUploader
  11.     ) {
  12.     }
  13.     public static function getSubscribedEvents(): array
  14.     {
  15.         return [
  16.             FileUploadEvent::class => 'onFileUpload',
  17.             FileDeleteEvent::class => 'onFileRemove',
  18.         ];
  19.     }
  20.     public function onFileUpload(FileUploadEvent $event): void
  21.     {
  22.         $this->fileUploader->uploadFile($event->getFile(), $event->getUploadedFile());
  23.     }
  24.     public function onFileRemove(FileDeleteEvent $event)
  25.     {
  26.         $this->fileUploader->deleteFile($event->getFile());
  27.     }
  28. }