Esempio n. 1
0
 /**
  * Store a file on the mongodb grid file system.
  *
  * @param string|GridFSFile $file String path to a file or a GridFSFile object.
  * @param object $document
  * @param array $options
  * @return GridFSFile $file
  */
 public function storeFile($file, array &$document, array $options = array())
 {
     if (is_string($file)) {
         $file = new GridFSFile($file);
     }
     if ($file->hasUnpersistedFile()) {
         $id = $this->mongoCollection->storeFile($file->getFilename(), $document, $options);
     } else {
         $id = $this->mongoCollection->storeBytes($file->getBytes(), $document, $options);
     }
     $document = array_merge(array('_id' => $id), $document);
     $file->setMongoGridFSFile(new \MongoGridFSFile($this->mongoCollection, $document));
     return $file;
 }
Esempio n. 2
0
 /**
  * Store a file on the mongodb grid file system.
  *
  * @param string|GridFSFile $file String path to a file or a GridFSFile object.
  * @param object $document
  * @param array $options
  * @return GridFSFile $file
  */
 public function storeFile($file, array &$document, array $options = array())
 {
     if (!$file instanceof GridFSFile) {
         $file = new GridFSFile($file);
     }
     if ($file->hasUnpersistedFile()) {
         $id = $this->getMongoCollection()->storeFile($file->getFilename(), $document, $options);
     } else {
         $id = $this->getMongoCollection()->storeBytes($file->getBytes(), $document, $options);
     }
     $document = array_merge(array('_id' => $id), $document);
     $gridFsFile = $this->getMongoCollection()->get($id);
     // TODO: Consider throwing exception if file cannot be fetched
     $file->setMongoGridFSFile($this->getMongoCollection()->get($id));
     return $file;
 }