public function getFileById($id)
{
if ($id instanceof \MongoId) {
$file = $this->getMongoCollection()->findOne(array('_id' => $id));
} else {
try {
$file = $this->getMongoCollection()->findOne(array('_id' => new \MongoId($id)));
} catch (\MongoException $e) {
$file = $this->getMongoCollection()->findOne(array('_id' => $id));
}
}
if (!$file) {
return null;
}
$fileClassName = $this->getFileClassName($file);
return new $fileClassName($this, $file);
}
public function testGetResource() { $id = $this->gridFs->storeBytes('somebinarydata', array('meta' => 1)); $this->assertTrue(is_resource($this->gridFs->getFileById($id)->getResource())); }