init
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\ImageManager\Plugin\MediaGallery;
|
||||
|
||||
use Esun\ImageManager\Model\MediaUploader;
|
||||
use Magento\Framework\App\Request\Http;
|
||||
use Magento\MediaGalleryUi\Model\UploadImage;
|
||||
|
||||
class SanitizePngUploadPlugin
|
||||
{
|
||||
public function __construct(
|
||||
private readonly Http $request,
|
||||
private readonly MediaUploader $mediaUploader
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize the temporary file before Magento Media Gallery creates its
|
||||
* uploader and invokes the environment-specific GD/libpng validator.
|
||||
*
|
||||
* @return array{0: string, 1: string}
|
||||
*/
|
||||
public function beforeExecute(UploadImage $subject, string $targetFolder, string $type): array
|
||||
{
|
||||
$file = $this->request->getFiles('image');
|
||||
if (is_array($file)
|
||||
&& !empty($file['tmp_name'])
|
||||
&& (int) ($file['error'] ?? UPLOAD_ERR_NO_FILE) === UPLOAD_ERR_OK
|
||||
) {
|
||||
$this->mediaUploader->sanitizePngUpload((string) $file['tmp_name']);
|
||||
}
|
||||
|
||||
return [$targetFolder, $type];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user