Exemplo n.º 1
0
 /**
  * Given a Doctrine mapped File instance, retrieves its data and fill
  * content local variable with it.
  *
  * @param FileInterface $file File to download
  *
  * @return FileInterface File downloaded
  */
 public function downloadFile(FileInterface $file)
 {
     /**
      * @var string $content
      */
     $content = $this->filesystem->read($this->fileIdentifierTransformer->transform($file));
     $file->setContent($content);
     return $file;
 }
Exemplo n.º 2
0
 /**
  * Steps necessary to store an image
  *
  * @param ObjectManager             $imageObjectManager        Image ObjectManager
  * @param ImageManager              $imageManager              ImageManager
  * @param Filesystem                $filesystem                Filesystem
  * @param fileIdentifierTransformer $fileIdentifierTransformer fileIdentifierTransformer
  * @param ProductInterface          $product                   Product
  * @param string                    $imageName                 Image name
  *
  * @return $this Self object
  */
 protected function storeImage(ObjectManager $imageObjectManager, ImageManager $imageManager, Filesystem $filesystem, FileIdentifierTransformerInterface $fileIdentifierTransformer, ProductInterface $product, $imageName)
 {
     $imagePath = realpath(dirname(__FILE__) . '/images/' . $imageName);
     $image = $imageManager->createImage(new File($imagePath));
     $image->setPath('products');
     $imageObjectManager->persist($image);
     $imageObjectManager->flush($image);
     $filesystem->write($fileIdentifierTransformer->transform($image), file_get_contents($imagePath), true);
     $product->addImage($image);
     $product->setPrincipalImage($image);
     return $this;
 }