Skip to content

Commit 7f8b770

Browse files
Roman HaninRoman Hanin
authored andcommitted
B2B-1610: Upgrade to Flysystem 2.0
- review notes fix.
1 parent 0ecc08e commit 7f8b770

File tree

6 files changed

+42
-85
lines changed

6 files changed

+42
-85
lines changed

app/code/Magento/AwsS3/Driver/AwsS3.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ public function isDirectory($path): bool
446446
$path = $this->normalizeRelativePath($path, true);
447447

448448
try {
449-
return $this->isMetadataTypeDirectory($path);
449+
return $this->isTypeDirectory($path);
450450
} catch (UnableToRetrieveMetadata $e) {
451451
try {
452452
return iterator_count($this->adapter->listContents($path, false)) > 0;
@@ -464,7 +464,7 @@ public function isDirectory($path): bool
464464
* @return bool
465465
* @throws UnableToRetrieveMetadata
466466
*/
467-
private function isMetadataTypeDirectory($path)
467+
private function isTypeDirectory($path)
468468
{
469469
$meta = $this->metadataProvider->getMetadata($path);
470470
if (isset($meta['type']) && $meta['type'] === self::TYPE_DIR) {

app/code/Magento/AwsS3/Driver/AwsS3Factory.php

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Magento\Framework\ObjectManagerInterface;
1414
use Magento\RemoteStorage\Driver\Adapter\Cache\CacheInterfaceFactory;
1515
use Magento\RemoteStorage\Driver\Adapter\CachedAdapterInterfaceFactory;
16-
use Magento\RemoteStorage\Driver\Adapter\MetadataProviderFactoryInterface;
16+
use Magento\RemoteStorage\Driver\Adapter\MetadataProviderInterfaceFactory;
1717
use Magento\RemoteStorage\Driver\DriverException;
1818
use Magento\RemoteStorage\Driver\DriverFactoryInterface;
1919
use Magento\RemoteStorage\Driver\RemoteDriverInterface;
@@ -35,7 +35,7 @@ class AwsS3Factory implements DriverFactoryInterface
3535
private $config;
3636

3737
/**
38-
* @var MetadataProviderFactoryInterface
38+
* @var MetadataProviderInterfaceFactory
3939
*/
4040
private $metadataProviderFactory;
4141

@@ -49,25 +49,33 @@ class AwsS3Factory implements DriverFactoryInterface
4949
*/
5050
private $cachedAdapterInterfaceFactory;
5151

52+
/**
53+
* @var string|null
54+
*/
55+
private $cachePrefix;
56+
5257
/**
5358
* @param ObjectManagerInterface $objectManager
5459
* @param Config $config
55-
* @param MetadataProviderFactoryInterface $metadataProviderFactory
60+
* @param MetadataProviderInterfaceFactory $metadataProviderFactory
5661
* @param CacheInterfaceFactory $cacheInterfaceFactory
5762
* @param CachedAdapterInterfaceFactory $cachedAdapterInterfaceFactory
63+
* @param string|null $cachePrefix
5864
*/
5965
public function __construct(
6066
ObjectManagerInterface $objectManager,
6167
Config $config,
62-
MetadataProviderFactoryInterface $metadataProviderFactory,
68+
MetadataProviderInterfaceFactory $metadataProviderFactory,
6369
CacheInterfaceFactory $cacheInterfaceFactory,
64-
CachedAdapterInterfaceFactory $cachedAdapterInterfaceFactory
70+
CachedAdapterInterfaceFactory $cachedAdapterInterfaceFactory,
71+
string $cachePrefix = null
6572
) {
6673
$this->objectManager = $objectManager;
6774
$this->config = $config;
6875
$this->metadataProviderFactory = $metadataProviderFactory;
6976
$this->cacheInterfaceFactory = $cacheInterfaceFactory;
7077
$this->cachedAdapterInterfaceFactory = $cachedAdapterInterfaceFactory;
78+
$this->cachePrefix = $cachePrefix;
7179
}
7280

7381
/**
@@ -110,17 +118,26 @@ public function createConfigured(
110118

111119
$client = new S3Client($config);
112120
$adapter = new AwsS3V3Adapter($client, $config['bucket'], $prefix);
113-
$cache = $this->cacheInterfaceFactory->create();
121+
$cache = $this->cacheInterfaceFactory->create(
122+
$this->cachePrefix ? ['prefix' => $this->cachePrefix] : []
123+
);
114124

115125
return $this->objectManager->create(
116126
AwsS3::class,
117127
[
118-
'adapter' => $this->cachedAdapterInterfaceFactory->create([
119-
'adapter' => $adapter,
120-
'cache' => $cache
121-
]),
128+
'adapter' => $this->cachedAdapterInterfaceFactory->create(
129+
[
130+
'adapter' => $adapter,
131+
'cache' => $cache
132+
]
133+
),
122134
'objectUrl' => $client->getObjectUrl($config['bucket'], trim($prefix, '\\/') . '/.'),
123-
'metadataProvider' => $this->metadataProviderFactory->create($adapter, $cache),
135+
'metadataProvider' => $this->metadataProviderFactory->create(
136+
[
137+
'adapter' => $adapter,
138+
'cache' => $cache
139+
]
140+
),
124141
]
125142
);
126143
}

app/code/Magento/RemoteStorage/Driver/Adapter/CachedAdapter.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class CachedAdapter implements CachedAdapterInterface
2828
private $cache;
2929

3030
/**
31-
* @var MetadataProviderFactoryInterface
31+
* @var MetadataProviderInterfaceFactory
3232
*/
3333
private $metadataProviderFactory;
3434

@@ -42,12 +42,12 @@ class CachedAdapter implements CachedAdapterInterface
4242
*
4343
* @param FilesystemAdapter $adapter
4444
* @param CacheInterface $cache
45-
* @param MetadataProviderFactoryInterface $metadataProviderFactory
45+
* @param MetadataProviderInterfaceFactory $metadataProviderFactory
4646
*/
4747
public function __construct(
4848
FilesystemAdapter $adapter,
4949
CacheInterface $cache,
50-
MetadataProviderFactoryInterface $metadataProviderFactory
50+
MetadataProviderInterfaceFactory $metadataProviderFactory
5151
) {
5252
$this->adapter = $adapter;
5353
$this->cache = $cache;
@@ -202,7 +202,12 @@ public function listContents(string $path, bool $deep): iterable
202202
private function getMetadata($path)
203203
{
204204
if (!$this->metadataProvider) {
205-
$this->metadataProvider = $this->metadataProviderFactory->create($this->adapter, $this->cache);
205+
$this->metadataProvider = $this->metadataProviderFactory->create(
206+
[
207+
'adapter' => $this->adapter,
208+
'cache' => $this->cache
209+
]
210+
);
206211
}
207212
return $this->metadataProvider->getMetadata($path);
208213
}

app/code/Magento/RemoteStorage/Driver/Adapter/MetadataProviderFactory.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

app/code/Magento/RemoteStorage/Driver/Adapter/MetadataProviderFactoryInterface.php

Lines changed: 0 additions & 26 deletions
This file was deleted.

app/code/Magento/RemoteStorage/Driver/Adapter/MetadataProviderInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Magento\RemoteStorage\Driver\Adapter;
99

10+
use League\Flysystem\UnableToRetrieveMetadata;
11+
1012
/**
1113
* Interface for metadata provider. Provides metadata of the file by given path.
1214
*/
@@ -17,6 +19,7 @@ interface MetadataProviderInterface
1719
*
1820
* @param string $path
1921
* @return array
22+
* @throws UnableToRetrieveMetadata
2023
*/
2124
public function getMetadata(string $path): array;
2225
}

0 commit comments

Comments
 (0)