<?php
namespace App\Infrastructure\File\EventSubscriber;
use App\Infrastructure\File\Event\FileDeleteEvent;
use App\Infrastructure\File\Event\FileUploadEvent;
use App\Infrastructure\File\Service\FileUploader;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class FileSubscriber implements EventSubscriberInterface
{
public function __construct(
private readonly FileUploader $fileUploader
) {
}
public static function getSubscribedEvents(): array
{
return [
FileUploadEvent::class => 'onFileUpload',
FileDeleteEvent::class => 'onFileRemove',
];
}
public function onFileUpload(FileUploadEvent $event): void
{
$this->fileUploader->uploadFile($event->getFile(), $event->getUploadedFile());
}
public function onFileRemove(FileDeleteEvent $event)
{
$this->fileUploader->deleteFile($event->getFile());
}
}