Skip to content

Removed fileinfo extension dependency from CMS module #29671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

19 changes: 14 additions & 5 deletions app/code/Magento/Cms/Model/Wysiwyg/Images/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* @SuppressWarnings(PHPMD.TooManyFields)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*
* @api
* @since 100.0.2
Expand Down Expand Up @@ -152,6 +153,11 @@ class Storage extends \Magento\Framework\DataObject
*/
private $ioFile;

/**
* @var \Magento\Framework\File\Mime|null
*/
private $mime;

/**
* Construct
*
Expand All @@ -174,6 +180,7 @@ class Storage extends \Magento\Framework\DataObject
* @param \Magento\Framework\Filesystem\DriverInterface $file
* @param \Magento\Framework\Filesystem\Io\File|null $ioFile
* @param \Psr\Log\LoggerInterface|null $logger
* @param \Magento\Framework\File\Mime $mime
*
* @throws \Magento\Framework\Exception\FileSystemException
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
Expand All @@ -197,7 +204,8 @@ public function __construct(
array $data = [],
\Magento\Framework\Filesystem\DriverInterface $file = null,
\Magento\Framework\Filesystem\Io\File $ioFile = null,
\Psr\Log\LoggerInterface $logger = null
\Psr\Log\LoggerInterface $logger = null,
\Magento\Framework\File\Mime $mime = null
) {
$this->_session = $session;
$this->_backendUrl = $backendUrl;
Expand All @@ -217,6 +225,7 @@ public function __construct(
$this->_dirs = $dirs;
$this->file = $file ?: ObjectManager::getInstance()->get(\Magento\Framework\Filesystem\Driver\File::class);
$this->ioFile = $ioFile ?: ObjectManager::getInstance()->get(\Magento\Framework\Filesystem\Io\File::class);
$this->mime = $mime ?: ObjectManager::getInstance()->get(\Magento\Framework\File\Mime::class);
parent::__construct($data);
}

Expand Down Expand Up @@ -362,7 +371,7 @@ public function getFilesCollection($path, $type = null)
$item->setUrl($this->_cmsWysiwygImages->getCurrentUrl() . $item->getBasename());
$itemStats = $this->file->stat($item->getFilename());
$item->setSize($itemStats['size']);
$item->setMimeType(\mime_content_type($item->getFilename()));
$item->setMimeType($this->mime->getMimeType($item->getFilename()));

if ($this->isImage($item->getBasename())) {
$thumbUrl = $this->getThumbnailUrl($item->getFilename(), true);
Expand Down Expand Up @@ -647,7 +656,7 @@ public function resizeFile($source, $keepRatio = true)
$image->keepAspectRatio($keepRatio);

list($imageWidth, $imageHeight) = $this->getResizedParams($source);

$image->resize($imageWidth, $imageHeight);
$dest = $targetDir . '/' . $this->ioFile->getPathInfo($source)['basename'];
$image->save($dest);
Expand All @@ -670,7 +679,7 @@ private function getResizedParams(string $source): array

//phpcs:ignore Generic.PHP.NoSilencedErrors
list($imageWidth, $imageHeight) = @getimagesize($source);

if ($imageWidth && $imageHeight) {
$imageWidth = $configWidth > $imageWidth ? $imageWidth : $configWidth;
$imageHeight = $configHeight > $imageHeight ? $imageHeight : $configHeight;
Expand All @@ -679,7 +688,7 @@ private function getResizedParams(string $source): array
}
return [$configWidth, $configHeight];
}

/**
* Resize images on the fly in controller action
*
Expand Down