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,19 @@ public function createMediaObjects(object $object): ?ArrayCollection
71
73
continue ;
72
74
}
73
75
74
- $ urlGenerator = $ this ->urlGenerators ->get ($ fieldConfiguration ->urlGenerator );
76
+ $ urlGeneratorReference = $ fieldConfiguration ->urlGenerator ?? 'api ' ;
77
+ $ urlGenerator = $ this ->urlGenerators ->get ($ urlGeneratorReference );
78
+ if ($ urlGenerator !== 'api ' ) {
79
+ $ adapter = $ this ->filesystemFactory ->getAdapter ($ fieldConfiguration ->adapter );
80
+ if (
81
+ ($ urlGenerator instanceof TemporaryUrlGenerator && !($ adapter instanceof \League \Flysystem \UrlGeneration \TemporaryUrlGenerator)) ||
82
+ ($ urlGenerator instanceof PublicUrlGenerator && !($ adapter instanceof \League \Flysystem \UrlGeneration \PublicUrlGenerator))
83
+ ) {
84
+ $ urlGeneratorReference = 'api ' ;
85
+ $ urlGenerator = $ this ->urlGenerators ->get ($ urlGeneratorReference );
86
+ }
87
+ }
88
+
75
89
if (!$ urlGenerator instanceof UploadableUrlGeneratorInterface) {
76
90
throw new InvalidArgumentException (sprintf ('The url generator provided must implement %s ' , UploadableUrlGeneratorInterface::class));
77
91
}
0 commit comments