Exemplo n.º 1
0
 /**
  * Retrieve a file content from a virtual file system.
  * In case no filesystem has this file registered, null is returned.
  *
  * @param string $path
  *
  * @throws NotLoadableException
  *
  * @return Binary|null|string
  */
 protected function retrieveContentFileFromVfs($path)
 {
     $content = null;
     $mimeType = null;
     foreach ($this->filesystemAliases as $alias) {
         $fs = $this->filesystemProvider->getFilesystem($alias);
         if ($fs->has($path)) {
             //TODO: we should use readStream, the problem is that
             // \Liip\ImagineBundle\Model\Binary expects the full content...
             $content = $fs->read($path);
             $mimeType = $fs->getMimetype($path);
         }
     }
     if (null === $content) {
         // the path is not stored on any vfs
         return null;
     }
     if (false === $content) {
         throw new NotLoadableException(sprintf('Unable to read the file "%s" from the filesystem.', $path));
     }
     if (false === $mimeType || null === $mimeType) {
         return $content;
     }
     return new Binary($content, $mimeType);
 }
 /**
  * @param ProductInterface   $fromProduct
  * @param ProductInterface   $toProduct
  * @param AttributeInterface $fromAttribute
  * @param AttributeInterface $toAttribute
  * @param string             $fromLocale
  * @param string             $toLocale
  * @param string             $fromScope
  * @param string             $toScope
  */
 protected function copySingleValue(ProductInterface $fromProduct, ProductInterface $toProduct, AttributeInterface $fromAttribute, AttributeInterface $toAttribute, $fromLocale, $toLocale, $fromScope, $toScope)
 {
     $fromValue = $fromProduct->getValue($fromAttribute->getCode(), $fromLocale, $fromScope);
     if (null !== $fromValue) {
         $toValue = $toProduct->getValue($toAttribute->getCode(), $toLocale, $toScope);
         if (null === $toValue) {
             $toValue = $this->productBuilder->addProductValue($toProduct, $toAttribute, $toLocale, $toScope);
         }
         $file = null;
         if (null !== $fromValue->getMedia()) {
             $filesystem = $this->filesystemProvider->getFilesystem(FileStorage::CATALOG_STORAGE_ALIAS);
             $rawFile = $this->fileFetcher->fetch($filesystem, $fromValue->getMedia()->getKey());
             $file = $this->fileStorer->store($rawFile, FileStorage::CATALOG_STORAGE_ALIAS, false);
             $file->setOriginalFilename($fromValue->getMedia()->getOriginalFilename());
         }
         $toValue->setMedia($file);
     }
 }
 /**
  * Fetch a media to the target
  *
  * @param array $media
  */
 protected function fetch(array $media)
 {
     try {
         $filesystem = $this->filesystemProvider->getFilesystem($media['storage']);
         $this->mediaFetcher->fetch($filesystem, $media['from'], $media['to']);
     } catch (FileTransferException $e) {
         $this->addError($media, sprintf('The media has not been found or is not currently available', $e->getMessage()));
     } catch (\LogicException $e) {
         $this->addError($media, sprintf('The media has not been copied. %s', $e->getMessage()));
     }
 }
Exemplo n.º 4
0
 /**
  * @param string $filename
  *
  * @throws NotFoundHttpException
  *
  * @return StreamedFileResponse
  */
 public function downloadAction($filename)
 {
     $filename = urldecode($filename);
     foreach ($this->filesystemAliases as $alias) {
         $fs = $this->filesystemProvider->getFilesystem($alias);
         if ($fs->has($filename)) {
             $stream = $fs->readStream($filename);
             $headers = [];
             if (null !== ($fileInfo = $this->fileInfoRepository->findOneByIdentifier($filename))) {
                 $headers['Content-Disposition'] = sprintf('attachment; filename="%s"', $fileInfo->getOriginalFilename());
             }
             return new StreamedFileResponse($stream, 200, $headers);
         }
     }
     throw new NotFoundHttpException(sprintf('File with key "%s" could not be found.', $filename));
 }
 function let(FilesystemProvider $filesystemProvider, FilesystemInterface $filesystem)
 {
     $filesystemProvider->getFilesystem(FileStorage::CATALOG_STORAGE_ALIAS)->willReturn($filesystem);
     $this->beConstructedWith($filesystemProvider, [FileStorage::CATALOG_STORAGE_ALIAS]);
 }