Ejemplo n.º 1
0
 public function testShouldNotConvertNestedUploadedFiles()
 {
     $tmpFile = $this->createTempFile();
     $file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', 100, 0);
     $bag = new FileBag(array('image' => array('file' => $file)));
     $files = $bag->all();
     $this->assertEquals($file, $files['image']['file']);
 }
Ejemplo n.º 2
0
 /**
  * @param \Symfony\Component\HttpFoundation\FileBag $fileBag
  * @param int                                       $id
  *
  * @return \Doctrine\Common\Collections\ArrayCollection
  */
 public function add(FileBag $fileBag, $id)
 {
     $urls = new ArrayCollection();
     foreach ($fileBag->all() as $file) {
         if ($file instanceof UploadedFile) {
             $uri = $this->processUploadedFile($file, $id);
             $urls->add($uri);
         }
     }
     return $urls;
 }
 /**
  *  Flattens a given filebag to extract all files.
  *
  *  @param bag The filebag to use
  *  @return array An array of files
  */
 protected function getFiles(FileBag $bag)
 {
     $files = array();
     $fileBag = $bag->all();
     $fileIterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($fileBag), \RecursiveIteratorIterator::SELF_FIRST);
     foreach ($fileIterator as $file) {
         if (is_array($file) || null === $file) {
             continue;
         }
         $files[] = $file;
     }
     return $files;
 }
Ejemplo n.º 4
0
 /**
  * Retrieve a file from the request.
  *
  * @param  string  $key
  * @param  mixed  $default
  * @return \Symfony\Component\HttpFoundation\File\UploadedFile|array|null
  */
 public function file($key = null, $default = null)
 {
     //        return data_get($this->allFiles(), $key, $default);
     return Arr::get($this->files->all(), $key, $default);
 }
Ejemplo n.º 5
0
 /**
  * @param FileBag|UploadedFile[] $images
  * @param Product                $product
  *
  * @throws \Symfony\Component\HttpFoundation\File\Exception\FileException
  */
 public function attachUploadedImagesToProduct($images, Product $product)
 {
     $product->attachImages(array_map(function (UploadedFile $image) {
         return $this->imageRepository->storeUploadedImage($image)->id;
     }, $images instanceof FileBag ? $images->all() : (array) $images));
 }