Skip to content

Commit 331c3fb

Browse files
committed
Updates due to Jeremy's review
1 parent 110eb84 commit 331c3fb

8 files changed

+30
-24
lines changed

docs/includes/apiargs-MongoDBDatabase-method-selectGridFSBucket-option.yaml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,11 @@ interface: phpmethod
1717
operation: ~
1818
optional: true
1919
---
20-
arg_name: option
21-
name: disableMD5
22-
type: boolean
23-
description: |
24-
Whether to disable automatic MD5 generation when storing files.
25-
26-
Defaults to ``false``.
27-
interface: phpmethod
28-
operation: ~
29-
optional: true
20+
source:
21+
file: apiargs-MongoDBGridFSBucket-common-option.yaml
22+
ref: disableMD5
23+
post: |
24+
.. versionadded: 1.4
3025
---
3126
source:
3227
file: apiargs-common-option.yaml

docs/includes/apiargs-MongoDBGridFSBucket-method-construct-option.yaml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,11 @@ interface: phpmethod
1717
operation: ~
1818
optional: true
1919
---
20-
arg_name: option
21-
name: disableMD5
22-
type: boolean
23-
description: |
24-
Whether to disable automatic MD5 generation when storing files.
25-
26-
Defaults to ``false``.
27-
interface: phpmethod
28-
operation: ~
29-
optional: true
20+
source:
21+
file: apiargs-MongoDBGridFSBucket-common-option.yaml
22+
ref: disableMD5
23+
post: |
24+
.. versionadded: 1.4
3025
---
3126
source:
3227
file: apiargs-common-option.yaml

docs/includes/apiargs-MongoDBGridFSBucket-method-openUploadStream-option.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ source:
99
source:
1010
file: apiargs-MongoDBGridFSBucket-common-option.yaml
1111
ref: disableMD5
12+
post: |
13+
.. versionadded: 1.4
1214
---
1315
source:
1416
file: apiargs-MongoDBGridFSBucket-common-option.yaml

docs/includes/apiargs-MongoDBGridFSBucket-method-uploadFromStream-option.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ source:
99
source:
1010
file: apiargs-MongoDBGridFSBucket-common-option.yaml
1111
ref: disableMD5
12+
post: |
13+
.. versionadded: 1.4
1214
---
1315
source:
1416
file: apiargs-MongoDBGridFSBucket-common-option.yaml

src/GridFS/Bucket.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public function __construct(Manager $manager, $databaseName, array $options = []
9090
$options += [
9191
'bucketName' => self::$defaultBucketName,
9292
'chunkSizeBytes' => self::$defaultChunkSizeBytes,
93+
'disableMD5' => false,
9394
];
9495

9596
if (isset($options['bucketName']) && ! is_string($options['bucketName'])) {
@@ -128,7 +129,7 @@ public function __construct(Manager $manager, $databaseName, array $options = []
128129
$this->databaseName = (string) $databaseName;
129130
$this->bucketName = $options['bucketName'];
130131
$this->chunkSizeBytes = $options['chunkSizeBytes'];
131-
$this->disableMD5 = isset($options['disableMD5']) ? $options['disableMD5'] : false;
132+
$this->disableMD5 = $options['disableMD5'];
132133
$this->readConcern = isset($options['readConcern']) ? $options['readConcern'] : $this->manager->getReadConcern();
133134
$this->readPreference = isset($options['readPreference']) ? $options['readPreference'] : $this->manager->getReadPreference();
134135
$this->typeMap = isset($options['typeMap']) ? $options['typeMap'] : self::$defaultTypeMap;
@@ -545,6 +546,9 @@ public function rename($id, $newFilename)
545546
* * chunkSizeBytes (integer): The chunk size in bytes. Defaults to the
546547
* bucket's chunk size.
547548
*
549+
* * disableMD5 (boolean): When true, no MD5 sum will be generated for
550+
* the stored file. Defaults to "false".
551+
*
548552
* * metadata (document): User data for the "metadata" field of the files
549553
* collection document.
550554
*

src/GridFS/WritableStream.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public function __construct(CollectionWrapper $collectionWrapper, $filename, arr
7676
$options += [
7777
'_id' => new ObjectId,
7878
'chunkSizeBytes' => self::$defaultChunkSizeBytes,
79+
'disableMD5' => false,
7980
];
8081

8182
if (isset($options['aliases']) && ! \MongoDB\is_string_array($options['aliases'])) {
@@ -104,7 +105,7 @@ public function __construct(CollectionWrapper $collectionWrapper, $filename, arr
104105

105106
$this->chunkSize = $options['chunkSizeBytes'];
106107
$this->collectionWrapper = $collectionWrapper;
107-
$this->disableMD5 = isset($options['disableMD5']) ? $options['disableMD5'] : false;
108+
$this->disableMD5 = $options['disableMD5'];
108109

109110
if ( ! $this->disableMD5) {
110111
$this->hashCtx = hash_init('md5');
@@ -235,8 +236,7 @@ private function fileCollectionInsert()
235236
$this->file['uploadDate'] = new UTCDateTime;
236237

237238
if ( ! $this->disableMD5) {
238-
$md5 = hash_final($this->hashCtx);
239-
$this->file['md5'] = $md5;
239+
$this->file['md5'] = hash_final($this->hashCtx);
240240
}
241241

242242
try {

tests/GridFS/BucketFunctionalTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ public function provideInvalidConstructorOptions()
5454
$options[][] = ['chunkSizeBytes' => $value];
5555
}
5656

57+
foreach ($this->getInvalidBooleanValues() as $value) {
58+
$options[][] = ['disableMD5' => $value];
59+
}
60+
5761
foreach ($this->getInvalidReadConcernValues() as $value) {
5862
$options[][] = ['readConcern' => $value];
5963
}

tests/GridFS/WritableStreamFunctionalTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ public function provideInvalidConstructorOptions()
4949
$options[][] = ['chunkSizeBytes' => $value];
5050
}
5151

52+
foreach ($this->getInvalidBooleanValues() as $value) {
53+
$options[][] = ['disableMD5' => $value];
54+
}
55+
5256
foreach ($this->getInvalidDocumentValues() as $value) {
5357
$options[][] = ['metadata' => $value];
5458
}

0 commit comments

Comments
 (0)