88namespace Magento \AwsS3 \Driver ;
99
1010use Exception ;
11- use League \Flysystem \AwsS3v3 \ AwsS3Adapter ;
11+ use League \Flysystem \AdapterInterface ;
1212use League \Flysystem \Config ;
1313use Magento \Framework \Exception \FileSystemException ;
1414use Magento \Framework \Filesystem \DriverInterface ;
@@ -32,30 +32,38 @@ class AwsS3 implements RemoteDriverInterface
3232 private const CONFIG = ['ACL ' => 'private ' ];
3333
3434 /**
35- * @var AwsS3Adapter
35+ * @var AdapterInterface
3636 */
3737 private $ adapter ;
3838
39+ /**
40+ * @var LoggerInterface
41+ */
42+ private $ logger ;
43+
3944 /**
4045 * @var array
4146 */
4247 private $ streams = [];
4348
4449 /**
45- * @var LoggerInterface
50+ * @var string
4651 */
47- private $ logger ;
52+ private $ objectUrl ;
4853
4954 /**
50- * @param AwsS3Adapter $adapter
55+ * @param AdapterInterface $adapter
5156 * @param LoggerInterface $logger
57+ * @param string $objectUrl
5258 */
5359 public function __construct (
54- AwsS3Adapter $ adapter ,
55- LoggerInterface $ logger
60+ AdapterInterface $ adapter ,
61+ LoggerInterface $ logger ,
62+ string $ objectUrl
5663 ) {
5764 $ this ->adapter = $ adapter ;
5865 $ this ->logger = $ logger ;
66+ $ this ->objectUrl = $ objectUrl ;
5967 }
6068
6169 /**
@@ -282,26 +290,27 @@ public function getAbsolutePath($basePath, $path, $scheme = null)
282290 * @param string $path Relative path
283291 * @return string Absolute path
284292 */
285- private function normalizeAbsolutePath (string $ path = '. ' ): string
293+ private function normalizeAbsolutePath (string $ path = '/ ' ): string
286294 {
287295 $ path = ltrim ($ path , '/ ' );
288- $ path = str_replace (
289- $ this ->adapter ->getClient ()->getObjectUrl (
290- $ this ->adapter ->getBucket (),
291- $ this ->adapter ->applyPathPrefix ('. ' )
292- ),
293- '' ,
294- $ path
295- );
296+ $ path = str_replace ($ this ->getObjectUrl ('' ), '' , $ path );
296297
297298 if (!$ path ) {
298- $ path = '. ' ;
299+ $ path = '/ ' ;
299300 }
300301
301- return $ this ->adapter ->getClient ()->getObjectUrl (
302- $ this ->adapter ->getBucket (),
303- $ this ->adapter ->applyPathPrefix ($ path )
304- );
302+ return $ this ->getObjectUrl ($ path );
303+ }
304+
305+ /**
306+ * Retrieves object URL from cache.
307+ *
308+ * @param string $path
309+ * @return string
310+ */
311+ private function getObjectUrl (string $ path ): string
312+ {
313+ return $ this ->objectUrl . ltrim ($ path , '/ ' );
305314 }
306315
307316 /**
@@ -312,11 +321,7 @@ private function normalizeAbsolutePath(string $path = '.'): string
312321 */
313322 private function normalizeRelativePath (string $ path ): string
314323 {
315- return str_replace (
316- $ this ->normalizeAbsolutePath (),
317- '' ,
318- $ path
319- );
324+ return str_replace ($ this ->normalizeAbsolutePath (), '' , $ path );
320325 }
321326
322327 /**
0 commit comments