/**
  * This method marks an entity to be uploaded as soon as the "flush" method of your object manager is called.
  * After calling this method, the file info you passed is set for this entity in the listener. This is all it takes
  * to upload a file for an entity in the Uploadable extension.
  *
  * @param object $entity   - The entity you are marking to "Upload" as soon as you call "flush".
  * @param mixed  $fileInfo - The file info object or array. In Symfony 2, this will be typically an UploadedFile instance.
  */
 public function markEntityToUpload($entity, $fileInfo)
 {
     if (is_object($fileInfo) && $fileInfo instanceof UploadedFile) {
         $fileInfoClass = $this->fileInfoClass;
         $fileInfo = new $fileInfoClass($fileInfo);
     }
     $this->listener->addEntityFileInfo($entity, $fileInfo);
 }
Пример #2
0
 /**
  * {@inheritDoc}
  */
 public function doMoveFile($source, $dest, $isUploadedFile = null)
 {
     if (null === $isUploadedFile) {
         return true;
     }
     return parent::doMoveFile($source, $dest, $isUploadedFile);
 }
 public function test_useGeneratedFilenameWhenAppendingNumbers()
 {
     // We set the default path on the listener
     $this->listener->setDefaultPath($this->destinationTestDir);
     $file = new FileWithAlphanumericName();
     $fileInfo = $this->generateUploadedFile('file', $this->testFileWithSpaces, $this->testFilenameWithSpaces);
     $this->listener->addEntityFileInfo($file, $fileInfo);
     $this->em->persist($file);
     $this->em->flush();
     $filePath = $file->getPath() . '/' . str_replace(' ', '-', $fileInfo['name']);
     $this->assertPathEquals($filePath, $file->getFilePath());
     $file = new FileWithAlphanumericName();
     $this->listener->addEntityFileInfo($file, $fileInfo);
     $this->em->persist($file);
     $this->em->flush();
     $filePath = $file->getPath() . '/' . str_replace(' ', '-', str_replace('.txt', '-2.txt', $fileInfo['name']));
     $this->assertPathEquals($filePath, $file->getFilePath());
 }
 public function doMoveFile($source, $dest, $isUploadedFile = true)
 {
     return $this->returnFalseOnMoveUploadedFile ? false : parent::doMoveFile($source, $dest, false);
 }
Пример #5
0
 /**
  * Set and validate default path
  * @param string $path
  * @throws FileNotFoundException
  * @throws InvalidStateException
  */
 public function setDefaultPath($path)
 {
     // Validate default path
     if (!file_exists($path) && !mkdir($path, 0777, TRUE)) {
         throw new FileNotFoundException("Default upload path: \"{$path}\" not found.");
     }
     if (!is_dir($path)) {
         throw new InvalidStateException("Default upload path: \"{$path}\" is not dir.");
     } else {
         if (!is_writable($path)) {
             throw new InvalidStateException("Default upload path: \"{$path}\" is not writable.");
         }
     }
     $path = self::normalizePath($path);
     parent::setDefaultPath($path);
 }