diff --git a/composer.json b/composer.json index 3c9bd9f..c0be205 100644 --- a/composer.json +++ b/composer.json @@ -28,6 +28,7 @@ "php": "^8.2", "doctrine/orm": "^2.10 || ^3.0", "symfony/deprecation-contracts": "^3.5", + "symfony/event-dispatcher": "^6.4 || ^7.0", "symfony/form": "^6.4 || ^7.0", "symfony/framework-bundle": "^6.4 || ^7.0", "symfony/http-foundation": "^6.4 || ^7.0", diff --git a/config/services.php b/config/services.php index b4089a5..d0e585d 100644 --- a/config/services.php +++ b/config/services.php @@ -37,6 +37,8 @@ use function Symfony\Component\DependencyInjection\Loader\Configurator\param; use function Symfony\Component\DependencyInjection\Loader\Configurator\service; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; + return static function (ContainerConfigurator $container): void { $container->services() // Controllers @@ -78,6 +80,7 @@ ->set(FileStorageManager::class) ->arg('$filesystemStorage', service(FilesystemStorage::class)) ->arg('$flysystemStorage', service(FlysystemStorage::class)) + ->arg('$eventDispatcher', service(EventDispatcherInterface::class)) // Form types ->set(FileType::class) diff --git a/src/Event/UploadedFileEvent.php b/src/Event/UploadedFileEvent.php new file mode 100644 index 0000000..3640cef --- /dev/null +++ b/src/Event/UploadedFileEvent.php @@ -0,0 +1,17 @@ +filesystemStorage->uploadFile($fileUploadConfig, $uploadedFile, $path, $filename); } + + $this->eventDispatcher->dispatch(new UploadedFileEvent(new \SplFileInfo($path . \DIRECTORY_SEPARATOR . $filename), $fileUploadConfig)); } public function removeFile(FileUploadConfig $fileUploadConfig, string $file): void diff --git a/tests/Listener/FileSubscriberTest.php b/tests/Listener/FileSubscriberTest.php index d9cb106..1b266cc 100644 --- a/tests/Listener/FileSubscriberTest.php +++ b/tests/Listener/FileSubscriberTest.php @@ -25,6 +25,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpFoundation\File\File; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; class FileSubscriberTest extends TestCase { @@ -46,6 +47,7 @@ protected function setUp(): void $fileStorageManager = new FileStorageManager( new FilesystemStorage($this->rootDir), new FlysystemStorage([]), + $this->createMock(EventDispatcherInterface::class), ); $this->subscriber = new FileSubscriber($fileStorageManager);