Skip to content

Commit 3fc31f4

Browse files
committed
Remove ExtendedDriverInterface from code
1 parent d7d86c4 commit 3fc31f4

File tree

8 files changed

+65
-12
lines changed

8 files changed

+65
-12
lines changed

app/code/Magento/Eav/Model/Attribute/Data/Image.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
namespace Magento\Eav\Model\Attribute\Data;
77

8-
use Magento\Framework\Filesystem\ExtendedDriverInterface;
8+
use Magento\RemoteStorage\Driver\RemoteDriverInterface;
99

1010
/**
1111
* EAV Entity Attribute Image File Data Model
@@ -29,7 +29,7 @@ protected function _validateByRules($value)
2929
{
3030
$label = __($this->getAttribute()->getStoreLabel());
3131
$rules = $this->getAttribute()->getValidateRules();
32-
$localStorage = !$this->_directory->getDriver() instanceof ExtendedDriverInterface;
32+
$localStorage = !$this->_directory->getDriver() instanceof RemoteDriverInterface;
3333
$imageProp = $localStorage
3434
? @getimagesize($value['tmp_name'])
3535
: $this->_directory->getDriver()->getMetadata($value['tmp_name']);

app/code/Magento/Eav/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"magento/module-catalog": "*",
1212
"magento/module-config": "*",
1313
"magento/module-media-storage": "*",
14-
"magento/module-store": "*"
14+
"magento/module-store": "*",
15+
"magento/module-remote-storage": "*"
1516
},
1617
"type": "magento2-module",
1718
"license": [

app/code/Magento/MediaGallerySynchronization/Model/CreateAssetFromFile.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\MediaGalleryApi\Api\Data\AssetInterfaceFactory;
1616
use Magento\MediaGallerySynchronization\Model\Filesystem\GetFileInfo;
1717
use Magento\MediaGallerySynchronizationApi\Model\CreateAssetFromFileInterface;
18+
use Magento\RemoteStorage\Driver\RemoteDriverInterface;
1819

1920
/**
2021
* Create media asset object based on the file information
@@ -75,7 +76,7 @@ public function execute(string $path): AssetInterface
7576
$absolutePath = $this->getMediaDirectory()->getAbsolutePath($path);
7677
$driver = $this->getMediaDirectory()->getDriver();
7778

78-
if ($driver instanceof Filesystem\ExtendedDriverInterface) {
79+
if ($driver instanceof RemoteDriverInterface) {
7980
$meta = $driver->getMetadata($absolutePath);
8081
} else {
8182
/**

app/code/Magento/MediaGallerySynchronization/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"magento/framework": "*",
77
"magento/module-media-gallery-api": "*",
88
"magento/module-media-gallery-synchronization-api": "*",
9-
"magento/framework-message-queue": "*"
9+
"magento/framework-message-queue": "*",
10+
"magento/module-remote-storage": "*"
1011
},
1112
"type": "magento2-module",
1213
"license": [

lib/internal/Magento/Framework/File/Mime.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Utility for mime type retrieval
1616
*
1717
* @deprecated
18-
* @see Filesystem\ExtendedDriverInterface::getMetadata()
18+
* @see Filesystem\DriverInterface::getMetadata()
1919
*/
2020
class Mime
2121
{
@@ -113,12 +113,16 @@ public function getMimeType($file)
113113
throw new FileSystemException(__("File '$file' doesn't exist"));
114114
}
115115

116-
if ($driver instanceof Filesystem\ExtendedDriverInterface) {
117-
return $driver->getMetadata($file)['mimetype'];
116+
$mimeType = '';
117+
if ($driver instanceof Filesystem\DriverInterface) {
118+
$mimeType = $driver->getMetadata($file)['mimetype'];
118119
}
119120

120-
$mime = new Filesystem\Driver\File\Mime();
121+
if (!$mimeType) {
122+
$mime = new Filesystem\Driver\File\Mime();
123+
$mimeType = $mime->getMimeType($file);
124+
}
121125

122-
return $mime->getMimeType($file);
126+
return $mimeType;
123127
}
124128
}

lib/internal/Magento/Framework/File/Test/Unit/MimeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class MimeTest extends TestCase
5656
protected function setUp(): void
5757
{
5858
$this->localDriverMock = $this->getMockForAbstractClass(Filesystem\DriverInterface::class);
59-
$this->remoteDriverMock = $this->getMockForAbstractClass(Filesystem\ExtendedDriverInterface::class);
59+
$this->remoteDriverMock = $this->getMockForAbstractClass(Filesystem\DriverInterface::class);
6060

6161
$this->localDirectoryMock = $this->getMockForAbstractClass(Filesystem\Directory\WriteInterface::class);
6262
$this->localDirectoryMock->method('getDriver')

lib/internal/Magento/Framework/Filesystem/Driver/File.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ public function getMetadata(string $path): array
11441144
*
11451145
* @return bool
11461146
*/
1147-
private function isFileAnImage(string $mimeType): bool
1147+
protected function isFileAnImage(string $mimeType): bool
11481148
{
11491149
return strstr($mimeType, 'image/');
11501150
}

lib/internal/Magento/Framework/Filesystem/Driver/Http.php

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

99
namespace Magento\Framework\Filesystem\Driver;
1010

11+
use League\Flysystem\AdapterInterface;
1112
use Magento\Framework\Exception\FileSystemException;
1213

1314
/**
@@ -22,6 +23,11 @@ class Http extends File
2223
*/
2324
protected $scheme = 'http';
2425

26+
/**
27+
* @var AdapterInterface
28+
*/
29+
private $adapter;
30+
2531
/**
2632
* Checks if path exists
2733
*
@@ -228,6 +234,46 @@ public function getAbsolutePath($basePath, $path, $scheme = null)
228234
return $this->getScheme() . $basePath . $path;
229235
}
230236

237+
/**
238+
* Retrieve file metadata.
239+
*
240+
* @param string $path
241+
*
242+
* @return array
243+
* @throws FileSystemException
244+
*/
245+
public function getMetadata(string $path): array
246+
{
247+
if (!$this->isExists($path)) {
248+
throw new FileSystemException(__("File '$path' doesn't exist"));
249+
}
250+
251+
$fileStat = $this->stat($path);
252+
$mimeType = $fileStat['type'] ?? '';
253+
254+
$file = new \SplFileInfo($path);
255+
256+
if ($this->isFileAnImage($mimeType)) {
257+
$imageInfo = getimagesize($this->getScheme() . $path);
258+
$mimeType = $imageInfo['mime'] ?? $mimeType;
259+
}
260+
261+
return [
262+
'path' => $file->getPath(),
263+
'dirname' => dirname($file->getPath()),
264+
'basename' => $file->getBasename(),
265+
'extension' => $file->getExtension(),
266+
'filename' => $file->getFilename(),
267+
'timestamp' => isset($fileStat['mtime']) ? strtotime($fileStat['mtime']) : 0,
268+
'size' => $fileStat['size'] ?? 0,
269+
'mimetype' => $mimeType,
270+
'extra' => [
271+
'image-width' => $imageInfo[0] ?? 0,
272+
'image-height' => $imageInfo[1] ?? 0
273+
]
274+
];
275+
}
276+
231277
/**
232278
* Return path with scheme
233279
*

0 commit comments

Comments
 (0)