Skip to content

Commit 823ed57

Browse files
committed
PHPLIB-198: Support readConcern option for GridFS collections
1 parent 42b3ad4 commit 823ed57

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/GridFS/Bucket.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use MongoDB\BSON\ObjectId;
66
use MongoDB\Driver\Cursor;
77
use MongoDB\Driver\Manager;
8+
use MongoDB\Driver\ReadConcern;
89
use MongoDB\Driver\ReadPreference;
910
use MongoDB\Driver\WriteConcern;
1011
use MongoDB\Exception\InvalidArgumentException;
@@ -38,6 +39,8 @@ class Bucket
3839
* * chunkSizeBytes (integer): The chunk size in bytes. Defaults to
3940
* 261120 (i.e. 255 KiB).
4041
*
42+
* * readConcern (MongoDB\Driver\ReadConcern): Read concern.
43+
*
4144
* * readPreference (MongoDB\Driver\ReadPreference): Read preference.
4245
*
4346
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern.
@@ -62,6 +65,10 @@ public function __construct(Manager $manager, $databaseName, array $options = []
6265
throw InvalidArgumentException::invalidType('"chunkSizeBytes" option', $options['chunkSizeBytes'], 'integer');
6366
}
6467

68+
if (isset($options['readConcern']) && ! $options['readConcern'] instanceof ReadConcern) {
69+
throw InvalidArgumentException::invalidType('"readConcern" option', $options['readConcern'], 'MongoDB\Driver\ReadConcern');
70+
}
71+
6572
if (isset($options['readPreference']) && ! $options['readPreference'] instanceof ReadPreference) {
6673
throw InvalidArgumentException::invalidType('"readPreference" option', $options['readPreference'], 'MongoDB\Driver\ReadPreference');
6774
}
@@ -73,7 +80,7 @@ public function __construct(Manager $manager, $databaseName, array $options = []
7380
$this->databaseName = (string) $databaseName;
7481
$this->options = $options;
7582

76-
$collectionOptions = array_intersect_key($options, ['readPreference' => 1, 'writeConcern' => 1]);
83+
$collectionOptions = array_intersect_key($options, ['readConcern' => 1, 'readPreference' => 1, 'writeConcern' => 1]);
7784

7885
$this->collectionWrapper = new CollectionWrapper($manager, $databaseName, $options['bucketName'], $collectionOptions);
7986
$this->registerStreamWrapper();

tests/GridFS/BucketFunctionalTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace MongoDB\Tests\GridFS;
44

55
use MongoDB\BSON\Binary;
6+
use MongoDB\Driver\ReadConcern;
67
use MongoDB\Driver\ReadPreference;
78
use MongoDB\Driver\WriteConcern;
89
use MongoDB\GridFS\Bucket;
@@ -21,6 +22,7 @@ public function testValidConstructorOptions()
2122
new Bucket($this->manager, $this->getDatabaseName(), [
2223
'bucketName' => 'test',
2324
'chunkSizeBytes' => 8192,
25+
'readConcern' => new ReadConcern(ReadConcern::LOCAL),
2426
'readPreference' => new ReadPreference(ReadPreference::RP_PRIMARY),
2527
'writeConcern' => new WriteConcern(WriteConcern::MAJORITY, 1000),
2628
]);
@@ -47,6 +49,10 @@ public function provideInvalidConstructorOptions()
4749
$options[][] = ['chunkSizeBytes' => $value];
4850
}
4951

52+
foreach ($this->getInvalidReadConcernValues() as $value) {
53+
$options[][] = ['readConcern' => $value];
54+
}
55+
5056
foreach ($this->getInvalidReadPreferenceValues() as $value) {
5157
$options[][] = ['readPreference' => $value];
5258
}

0 commit comments

Comments
 (0)