Commit 2e9b3268 authored by Jeremy Mikola's avatar Jeremy Mikola

Merge pull request #197

parents 42b3ad4a 823ed577
...@@ -5,6 +5,7 @@ namespace MongoDB\GridFS; ...@@ -5,6 +5,7 @@ namespace MongoDB\GridFS;
use MongoDB\BSON\ObjectId; use MongoDB\BSON\ObjectId;
use MongoDB\Driver\Cursor; use MongoDB\Driver\Cursor;
use MongoDB\Driver\Manager; use MongoDB\Driver\Manager;
use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference; use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
...@@ -38,6 +39,8 @@ class Bucket ...@@ -38,6 +39,8 @@ class Bucket
* * chunkSizeBytes (integer): The chunk size in bytes. Defaults to * * chunkSizeBytes (integer): The chunk size in bytes. Defaults to
* 261120 (i.e. 255 KiB). * 261120 (i.e. 255 KiB).
* *
* * readConcern (MongoDB\Driver\ReadConcern): Read concern.
*
* * readPreference (MongoDB\Driver\ReadPreference): Read preference. * * readPreference (MongoDB\Driver\ReadPreference): Read preference.
* *
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern. * * writeConcern (MongoDB\Driver\WriteConcern): Write concern.
...@@ -62,6 +65,10 @@ class Bucket ...@@ -62,6 +65,10 @@ class Bucket
throw InvalidArgumentException::invalidType('"chunkSizeBytes" option', $options['chunkSizeBytes'], 'integer'); throw InvalidArgumentException::invalidType('"chunkSizeBytes" option', $options['chunkSizeBytes'], 'integer');
} }
if (isset($options['readConcern']) && ! $options['readConcern'] instanceof ReadConcern) {
throw InvalidArgumentException::invalidType('"readConcern" option', $options['readConcern'], 'MongoDB\Driver\ReadConcern');
}
if (isset($options['readPreference']) && ! $options['readPreference'] instanceof ReadPreference) { if (isset($options['readPreference']) && ! $options['readPreference'] instanceof ReadPreference) {
throw InvalidArgumentException::invalidType('"readPreference" option', $options['readPreference'], 'MongoDB\Driver\ReadPreference'); throw InvalidArgumentException::invalidType('"readPreference" option', $options['readPreference'], 'MongoDB\Driver\ReadPreference');
} }
...@@ -73,7 +80,7 @@ class Bucket ...@@ -73,7 +80,7 @@ class Bucket
$this->databaseName = (string) $databaseName; $this->databaseName = (string) $databaseName;
$this->options = $options; $this->options = $options;
$collectionOptions = array_intersect_key($options, ['readPreference' => 1, 'writeConcern' => 1]); $collectionOptions = array_intersect_key($options, ['readConcern' => 1, 'readPreference' => 1, 'writeConcern' => 1]);
$this->collectionWrapper = new CollectionWrapper($manager, $databaseName, $options['bucketName'], $collectionOptions); $this->collectionWrapper = new CollectionWrapper($manager, $databaseName, $options['bucketName'], $collectionOptions);
$this->registerStreamWrapper(); $this->registerStreamWrapper();
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace MongoDB\Tests\GridFS; namespace MongoDB\Tests\GridFS;
use MongoDB\BSON\Binary; use MongoDB\BSON\Binary;
use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference; use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\GridFS\Bucket; use MongoDB\GridFS\Bucket;
...@@ -21,6 +22,7 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -21,6 +22,7 @@ class BucketFunctionalTest extends FunctionalTestCase
new Bucket($this->manager, $this->getDatabaseName(), [ new Bucket($this->manager, $this->getDatabaseName(), [
'bucketName' => 'test', 'bucketName' => 'test',
'chunkSizeBytes' => 8192, 'chunkSizeBytes' => 8192,
'readConcern' => new ReadConcern(ReadConcern::LOCAL),
'readPreference' => new ReadPreference(ReadPreference::RP_PRIMARY), 'readPreference' => new ReadPreference(ReadPreference::RP_PRIMARY),
'writeConcern' => new WriteConcern(WriteConcern::MAJORITY, 1000), 'writeConcern' => new WriteConcern(WriteConcern::MAJORITY, 1000),
]); ]);
...@@ -47,6 +49,10 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -47,6 +49,10 @@ class BucketFunctionalTest extends FunctionalTestCase
$options[][] = ['chunkSizeBytes' => $value]; $options[][] = ['chunkSizeBytes' => $value];
} }
foreach ($this->getInvalidReadConcernValues() as $value) {
$options[][] = ['readConcern' => $value];
}
foreach ($this->getInvalidReadPreferenceValues() as $value) { foreach ($this->getInvalidReadPreferenceValues() as $value) {
$options[][] = ['readPreference' => $value]; $options[][] = ['readPreference' => $value];
} }
......
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