2323use Silverback \ApiComponentsBundle \Entity \Core \FileInfo ;
2424use Silverback \ApiComponentsBundle \Entity \Utility \ImagineFiltersInterface ;
2525use Silverback \ApiComponentsBundle \Exception \InvalidArgumentException ;
26+ use Silverback \ApiComponentsBundle \Flysystem \FilesystemFactory ;
2627use Silverback \ApiComponentsBundle \Flysystem \FilesystemProvider ;
2728use Silverback \ApiComponentsBundle \Helper \Uploadable \FileInfoCacheManager ;
2829use Silverback \ApiComponentsBundle \Imagine \FlysystemDataLoader ;
@@ -46,6 +47,7 @@ public function __construct(
4647 private readonly FlysystemDataLoader $ flysystemDataLoader ,
4748 private readonly RequestStack $ requestStack ,
4849 private readonly ServiceLocator $ urlGenerators ,
50+ private readonly FilesystemFactory $ filesystemFactory ,
4951 private readonly ?FilterService $ filterService = null
5052 ) {
5153 $ this ->initRegistry ($ managerRegistry );
@@ -71,7 +73,20 @@ public function createMediaObjects(object $object): ?ArrayCollection
7173 continue ;
7274 }
7375
74- $ urlGenerator = $ this ->urlGenerators ->get ($ fieldConfiguration ->urlGenerator );
76+ // todo: consultation on perhaps attributes which can be configured with environment variables or best way to achieve easier implementation
77+ $ urlGeneratorReference = $ fieldConfiguration ->urlGenerator ?? 'api ' ;
78+ $ urlGenerator = $ this ->urlGenerators ->get ($ urlGeneratorReference );
79+ if ($ urlGenerator !== 'api ' ) {
80+ $ adapter = $ this ->filesystemFactory ->getAdapter ($ fieldConfiguration ->adapter );
81+ if (
82+ ($ urlGenerator instanceof TemporaryUrlGenerator && !($ adapter instanceof \League \Flysystem \UrlGeneration \TemporaryUrlGenerator)) ||
83+ ($ urlGenerator instanceof PublicUrlGenerator && !($ adapter instanceof \League \Flysystem \UrlGeneration \PublicUrlGenerator))
84+ ) {
85+ $ urlGeneratorReference = 'api ' ;
86+ $ urlGenerator = $ this ->urlGenerators ->get ($ urlGeneratorReference );
87+ }
88+ }
89+
7590 if (!$ urlGenerator instanceof UploadableUrlGeneratorInterface) {
7691 throw new InvalidArgumentException (sprintf ('The url generator provided must implement %s ' , UploadableUrlGeneratorInterface::class));
7792 }
0 commit comments