/** * Wrapper method for MongoGridFS::storeFile(). * * This method returns the GridFSFile object, unlike the base MongoGridFS * method, which returns the "_id" field of the saved document. The "_id" * will be set on the $document parameter, which is passed by reference. * * @see http://php.net/manual/en/mongogridfs.storefile.php * @param string|GridFSFile $file String filename or a GridFSFile object * @param array $document * @param array $options * @return GridFSFile */ public function storeFile($file, array &$document, array $options = []) { if (!$file instanceof GridFSFile) { $file = new GridFSFile($file); } $options = isset($options['safe']) ? $this->convertWriteConcern($options) : $options; if ($file->hasUnpersistedFile()) { $id = $this->mongoCollection->storeFile($file->getFilename(), $document, $options); } else { $id = $this->mongoCollection->storeBytes($file->getBytes(), $document, $options); } $document = array_merge(['_id' => $id], $document); $gridFsFile = $this->mongoCollection->get($id); // TODO: Consider throwing exception if file cannot be fetched $file->setMongoGridFSFile($this->mongoCollection->get($id)); return $file; }
public function testGetBytesWithEmptyState() { $file = new GridFSFile(); $this->assertNull($file->getBytes()); }