23
23
use Silverback \ApiComponentsBundle \Entity \Core \FileInfo ;
24
24
use Silverback \ApiComponentsBundle \Entity \Utility \ImagineFiltersInterface ;
25
25
use Silverback \ApiComponentsBundle \Exception \InvalidArgumentException ;
26
+ use Silverback \ApiComponentsBundle \Flysystem \FilesystemFactory ;
26
27
use Silverback \ApiComponentsBundle \Flysystem \FilesystemProvider ;
27
28
use Silverback \ApiComponentsBundle \Helper \Uploadable \FileInfoCacheManager ;
28
29
use Silverback \ApiComponentsBundle \Imagine \FlysystemDataLoader ;
@@ -46,6 +47,7 @@ public function __construct(
46
47
private readonly FlysystemDataLoader $ flysystemDataLoader ,
47
48
private readonly RequestStack $ requestStack ,
48
49
private readonly ServiceLocator $ urlGenerators ,
50
+ private readonly FilesystemFactory $ filesystemFactory ,
49
51
private readonly ?FilterService $ filterService = null
50
52
) {
51
53
$ this ->initRegistry ($ managerRegistry );
@@ -71,7 +73,20 @@ public function createMediaObjects(object $object): ?ArrayCollection
71
73
continue ;
72
74
}
73
75
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
+
75
90
if (!$ urlGenerator instanceof UploadableUrlGeneratorInterface) {
76
91
throw new InvalidArgumentException (sprintf ('The url generator provided must implement %s ' , UploadableUrlGeneratorInterface::class));
77
92
}
0 commit comments