/** * Check if gallery entry content is valid * * @param ProductAttributeMediaGalleryEntryContentInterface $entryContent * @return bool * @throws InputException */ public function isValid(ProductAttributeMediaGalleryEntryContentInterface $entryContent) { $fileContent = @base64_decode($entryContent->getEntryData(), true); if (empty($fileContent)) { throw new InputException('The image content must be valid base64 encoded data.'); } $imageProperties = @getimagesizefromstring($fileContent); if (empty($imageProperties)) { throw new InputException('The image content must be valid base64 encoded data.'); } $sourceMimeType = $imageProperties['mime']; if ($sourceMimeType != $entryContent->getMimeType() || !$this->isMimeTypeValid($sourceMimeType)) { throw new InputException('The image MIME type is not valid or not supported.'); } if (!$this->isNameValid($entryContent->getName())) { throw new InputException('Provided image name contains forbidden characters.'); } return true; }
/** * @param ProductAttributeMediaGalleryEntryContentInterface $content * @return array */ protected function convertFromMediaGalleryEntryContentInterface(ProductAttributeMediaGalleryEntryContentInterface $content = null) { if ($content == null) { return null; } else { return ["entry_data" => $content->getEntryData(), "mime_type" => $content->getMimeType(), "name" => $content->getName()]; } }