/**
  * @param ImageContentInterface $content
  * @return array
  */
 protected function convertFromMediaGalleryEntryContentInterface(ImageContentInterface $content = null)
 {
     if ($content == null) {
         return null;
     } else {
         return ['data' => [ImageContentInterface::BASE64_ENCODED_DATA => $content->getBase64EncodedData(), ImageContentInterface::TYPE => $content->getType(), ImageContentInterface::NAME => $content->getName()]];
     }
 }
 /**
  * Check if gallery entry content is valid
  *
  * @param ImageContentInterface $imageContent
  * @return bool
  * @throws InputException
  */
 public function isValid(ImageContentInterface $imageContent)
 {
     $fileContent = @base64_decode($imageContent->getBase64EncodedData(), true);
     if (empty($fileContent)) {
         throw new InputException(new Phrase('The image content must be valid base64 encoded data.'));
     }
     $imageProperties = @getimagesizefromstring($fileContent);
     if (empty($imageProperties)) {
         throw new InputException(new Phrase('The image content must be valid base64 encoded data.'));
     }
     $sourceMimeType = $imageProperties['mime'];
     if ($sourceMimeType != $imageContent->getType() || !$this->isMimeTypeValid($sourceMimeType)) {
         throw new InputException(new Phrase('The image MIME type is not valid or not supported.'));
     }
     if (!$this->isNameValid($imageContent->getName())) {
         throw new InputException(new Phrase('Provided image name contains forbidden characters.'));
     }
     return true;
 }
Пример #3
0
 /**
  * @param ImageContentInterface $imageContent
  * @return string
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 private function getFileName($imageContent)
 {
     $fileName = $imageContent->getName();
     if (!pathinfo($fileName, PATHINFO_EXTENSION)) {
         if (!$imageContent->getType() || !$this->getMimeTypeExtension($imageContent->getType())) {
             throw new InputException(new Phrase('Cannot recognize image extension.'));
         }
         $fileName .= '.' . $this->getMimeTypeExtension($imageContent->getType());
     }
     return $fileName;
 }