Skip to content
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

Removed fileinfo extension dependency from CMS module #29671

17 changes: 13 additions & 4 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.CyclomaticComplexity)
engcom-Charlie marked this conversation as resolved.
Show resolved Hide resolved
*
* @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 @@ -173,6 +179,7 @@ class Storage extends \Magento\Framework\DataObject
* @param array $data
* @param \Magento\Framework\Filesystem\DriverInterface $file
* @param \Magento\Framework\Filesystem\Io\File|null $ioFile
* @param \Magento\Framework\File\Mime $mime
* @param \Psr\Log\LoggerInterface|null $logger
*
* @throws \Magento\Framework\Exception\FileSystemException
Expand All @@ -197,6 +204,7 @@ public function __construct(
array $data = [],
\Magento\Framework\Filesystem\DriverInterface $file = null,
\Magento\Framework\Filesystem\Io\File $ioFile = null,
\Magento\Framework\File\Mime $mime = null,
ihor-sviziev marked this conversation as resolved.
Show resolved Hide resolved
\Psr\Log\LoggerInterface $logger = null
) {
$this->_session = $session;
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