Commit c94fa5f0 authored by Jeremy Mikola's avatar Jeremy Mikola

Implement Bucket::getBucketName() and debug handler

parent d3153e97
......@@ -26,7 +26,8 @@ class Bucket
private $collectionWrapper;
private $databaseName;
private $options;
private $bucketName;
private $chunkSizeBytes;
/**
* Constructs a GridFS bucket.
......@@ -78,7 +79,8 @@ class Bucket
}
$this->databaseName = (string) $databaseName;
$this->options = $options;
$this->bucketName = $options['bucketName'];
$this->chunkSizeBytes = $options['chunkSizeBytes'];
$collectionOptions = array_intersect_key($options, ['readConcern' => 1, 'readPreference' => 1, 'writeConcern' => 1]);
......@@ -86,6 +88,21 @@ class Bucket
$this->registerStreamWrapper();
}
/**
* Return internal properties for debugging purposes.
*
* @see http://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.debuginfo
* @return array
*/
public function __debugInfo()
{
return [
'bucketName' => $this->bucketName,
'databaseName' => $this->databaseName,
'chunkSizeBytes' => $this->chunkSizeBytes,
];
}
/**
* Delete a file from the GridFS bucket.
*
......@@ -179,6 +196,21 @@ class Bucket
return $this->collectionWrapper->findFiles($filter, $options);
}
/**
* Return the bucket name.
*
* @return string
*/
public function getBucketName()
{
return $this->bucketName;
}
/**
* Return the database name.
*
* @return string
*/
public function getDatabaseName()
{
return $this->databaseName;
......@@ -275,7 +307,7 @@ class Bucket
*/
public function openUploadStream($filename, array $options = [])
{
$options += ['chunkSizeBytes' => $this->options['chunkSizeBytes']];
$options += ['chunkSizeBytes' => $this->chunkSizeBytes];
$path = $this->createPathForUpload();
$context = stream_context_create([
......@@ -367,7 +399,7 @@ class Bucket
'%s://%s/%s.files/%s',
self::$streamWrapperProtocol,
urlencode($this->databaseName),
urlencode($this->options['bucketName']),
urlencode($this->bucketName),
urlencode($id)
);
}
......@@ -383,7 +415,7 @@ class Bucket
'%s://%s/%s.files',
self::$streamWrapperProtocol,
urlencode($this->databaseName),
urlencode($this->options['bucketName'])
urlencode($this->bucketName)
);
}
......@@ -394,7 +426,7 @@ class Bucket
*/
private function getFilesNamespace()
{
return sprintf('%s.%s.files', $this->databaseName, $this->options['bucketName']);
return sprintf('%s.%s.files', $this->databaseName, $this->bucketName);
}
/**
......
......@@ -306,6 +306,18 @@ class BucketFunctionalTest extends FunctionalTestCase
$this->assertSameDocuments($expected, $cursor);
}
public function testGetBucketNameWithCustomValue()
{
$bucket = new Bucket($this->manager, $this->getDatabaseName(), ['bucketName' => 'custom_fs']);
$this->assertEquals('custom_fs', $bucket->getBucketName());
}
public function testGetBucketNameWithDefaultValue()
{
$this->assertEquals('fs', $this->bucket->getBucketName());
}
public function testGetDatabaseName()
{
$this->assertEquals($this->getDatabaseName(), $this->bucket->getDatabaseName());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment