Skip to content

Commit 8344b11

Browse files
Removed fileinfo extension dependency from CMS module
1 parent bdde24b commit 8344b11

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

app/code/Magento/Cms/Model/Wysiwyg/Images/Storage.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ class Storage extends \Magento\Framework\DataObject
152152
*/
153153
private $ioFile;
154154

155+
/**
156+
* @var \Magento\Framework\File\Mime|null
157+
*/
158+
private $mime;
159+
155160
/**
156161
* Construct
157162
*
@@ -197,6 +202,7 @@ public function __construct(
197202
array $data = [],
198203
\Magento\Framework\Filesystem\DriverInterface $file = null,
199204
\Magento\Framework\Filesystem\Io\File $ioFile = null,
205+
\Magento\Framework\File\Mime $mime = null,
200206
\Psr\Log\LoggerInterface $logger = null
201207
) {
202208
$this->_session = $session;
@@ -217,6 +223,7 @@ public function __construct(
217223
$this->_dirs = $dirs;
218224
$this->file = $file ?: ObjectManager::getInstance()->get(\Magento\Framework\Filesystem\Driver\File::class);
219225
$this->ioFile = $ioFile ?: ObjectManager::getInstance()->get(\Magento\Framework\Filesystem\Io\File::class);
226+
$this->mime = $mime ?: ObjectManager::getInstance()->get(\Magento\Framework\File\Mime::class);
220227
parent::__construct($data);
221228
}
222229

@@ -362,7 +369,7 @@ public function getFilesCollection($path, $type = null)
362369
$item->setUrl($this->_cmsWysiwygImages->getCurrentUrl() . $item->getBasename());
363370
$itemStats = $this->file->stat($item->getFilename());
364371
$item->setSize($itemStats['size']);
365-
$item->setMimeType(\mime_content_type($item->getFilename()));
372+
$item->setMimeType($this->mime->getMimeType($item->getFilename()));
366373

367374
if ($this->isImage($item->getBasename())) {
368375
$thumbUrl = $this->getThumbnailUrl($item->getFilename(), true);
@@ -647,7 +654,7 @@ public function resizeFile($source, $keepRatio = true)
647654
$image->keepAspectRatio($keepRatio);
648655

649656
list($imageWidth, $imageHeight) = $this->getResizedParams($source);
650-
657+
651658
$image->resize($imageWidth, $imageHeight);
652659
$dest = $targetDir . '/' . $this->ioFile->getPathInfo($source)['basename'];
653660
$image->save($dest);
@@ -670,7 +677,7 @@ private function getResizedParams(string $source): array
670677

671678
//phpcs:ignore Generic.PHP.NoSilencedErrors
672679
list($imageWidth, $imageHeight) = @getimagesize($source);
673-
680+
674681
if ($imageWidth && $imageHeight) {
675682
$imageWidth = $configWidth > $imageWidth ? $imageWidth : $configWidth;
676683
$imageHeight = $configHeight > $imageHeight ? $imageHeight : $configHeight;
@@ -679,7 +686,7 @@ private function getResizedParams(string $source): array
679686
}
680687
return [$configWidth, $configHeight];
681688
}
682-
689+
683690
/**
684691
* Resize images on the fly in controller action
685692
*

0 commit comments

Comments
 (0)