Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
mongo-php-library
Commits
f169616c
Commit
f169616c
authored
Jun 21, 2018
by
Derick Rethans
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-319: Added 'disableMD5' option as GridFS MD5 digest must be optional
parent
baf85f46
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
154 additions
and
6 deletions
+154
-6
apiargs-MongoDBDatabase-method-selectGridFSBucket-option.yaml
...rgs-MongoDBDatabase-method-selectGridFSBucket-option.yaml
+11
-0
apiargs-MongoDBGridFSBucket-common-option.yaml
docs/includes/apiargs-MongoDBGridFSBucket-common-option.yaml
+11
-0
apiargs-MongoDBGridFSBucket-method-construct-option.yaml
.../apiargs-MongoDBGridFSBucket-method-construct-option.yaml
+11
-0
apiargs-MongoDBGridFSBucket-method-openUploadStream-option.yaml
...s-MongoDBGridFSBucket-method-openUploadStream-option.yaml
+4
-0
apiargs-MongoDBGridFSBucket-method-uploadFromStream-option.yaml
...s-MongoDBGridFSBucket-method-uploadFromStream-option.yaml
+4
-0
Bucket.php
src/GridFS/Bucket.php
+12
-0
WritableStream.php
src/GridFS/WritableStream.php
+22
-6
upload.json
tests/GridFS/spec-tests/upload.json
+79
-0
No files found.
docs/includes/apiargs-MongoDBDatabase-method-selectGridFSBucket-option.yaml
View file @
f169616c
...
...
@@ -17,6 +17,17 @@ interface: phpmethod
operation
:
~
optional
:
true
---
arg_name
:
option
name
:
disableMD5
type
:
boolean
description
:
|
Whether to disable automatic MD5 generation when storing files.
Defaults to ``false``.
interface
:
phpmethod
operation
:
~
optional
:
true
---
source
:
file
:
apiargs-common-option.yaml
ref
:
readConcern
...
...
docs/includes/apiargs-MongoDBGridFSBucket-common-option.yaml
View file @
f169616c
...
...
@@ -18,6 +18,17 @@ operation: ~
optional
:
true
---
arg_name
:
option
name
:
disableMD5
type
:
boolean
description
:
|
Whether to disable automatic MD5 generation when storing files.
Defaults to ``false``.
interface
:
phpmethod
operation
:
~
optional
:
true
---
arg_name
:
option
name
:
metadata
type
:
array|object
description
:
|
...
...
docs/includes/apiargs-MongoDBGridFSBucket-method-construct-option.yaml
View file @
f169616c
...
...
@@ -17,6 +17,17 @@ interface: phpmethod
operation
:
~
optional
:
true
---
arg_name
:
option
name
:
disableMD5
type
:
boolean
description
:
|
Whether to disable automatic MD5 generation when storing files.
Defaults to ``false``.
interface
:
phpmethod
operation
:
~
optional
:
true
---
source
:
file
:
apiargs-common-option.yaml
ref
:
readConcern
...
...
docs/includes/apiargs-MongoDBGridFSBucket-method-openUploadStream-option.yaml
View file @
f169616c
...
...
@@ -6,6 +6,10 @@ source:
file
:
apiargs-MongoDBGridFSBucket-common-option.yaml
ref
:
chunkSizeBytes
---
source
:
file
:
apiargs-MongoDBGridFSBucket-common-option.yaml
ref
:
disableMD5
---
source
:
file
:
apiargs-MongoDBGridFSBucket-common-option.yaml
ref
:
metadata
...
...
docs/includes/apiargs-MongoDBGridFSBucket-method-uploadFromStream-option.yaml
View file @
f169616c
...
...
@@ -6,6 +6,10 @@ source:
file
:
apiargs-MongoDBGridFSBucket-common-option.yaml
ref
:
chunkSizeBytes
---
source
:
file
:
apiargs-MongoDBGridFSBucket-common-option.yaml
ref
:
disableMD5
---
source
:
file
:
apiargs-MongoDBGridFSBucket-common-option.yaml
ref
:
metadata
...
...
src/GridFS/Bucket.php
View file @
f169616c
...
...
@@ -51,6 +51,7 @@ class Bucket
private
$databaseName
;
private
$manager
;
private
$bucketName
;
private
$disableMD5
;
private
$chunkSizeBytes
;
private
$readConcern
;
private
$readPreference
;
...
...
@@ -68,6 +69,9 @@ class Bucket
* * chunkSizeBytes (integer): The chunk size in bytes. Defaults to
* 261120 (i.e. 255 KiB).
*
* * disableMD5 (boolean): When true, no MD5 sum will be generated for
* each stored file. Defaults to "false".
*
* * readConcern (MongoDB\Driver\ReadConcern): Read concern.
*
* * readPreference (MongoDB\Driver\ReadPreference): Read preference.
...
...
@@ -100,6 +104,10 @@ class Bucket
throw
new
InvalidArgumentException
(
sprintf
(
'Expected "chunkSizeBytes" option to be >= 1, %d given'
,
$options
[
'chunkSizeBytes'
]));
}
if
(
isset
(
$options
[
'disableMD5'
])
&&
!
is_bool
(
$options
[
'disableMD5'
]))
{
throw
InvalidArgumentException
::
invalidType
(
'"disableMD5" option'
,
$options
[
'disableMD5'
],
'boolean'
);
}
if
(
isset
(
$options
[
'readConcern'
])
&&
!
$options
[
'readConcern'
]
instanceof
ReadConcern
)
{
throw
InvalidArgumentException
::
invalidType
(
'"readConcern" option'
,
$options
[
'readConcern'
],
'MongoDB\Driver\ReadConcern'
);
}
...
...
@@ -120,6 +128,7 @@ class Bucket
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
bucketName
=
$options
[
'bucketName'
];
$this
->
chunkSizeBytes
=
$options
[
'chunkSizeBytes'
];
$this
->
disableMD5
=
isset
(
$options
[
'disableMD5'
])
?
$options
[
'disableMD5'
]
:
false
;
$this
->
readConcern
=
isset
(
$options
[
'readConcern'
])
?
$options
[
'readConcern'
]
:
$this
->
manager
->
getReadConcern
();
$this
->
readPreference
=
isset
(
$options
[
'readPreference'
])
?
$options
[
'readPreference'
]
:
$this
->
manager
->
getReadPreference
();
$this
->
typeMap
=
isset
(
$options
[
'typeMap'
])
?
$options
[
'typeMap'
]
:
self
::
$defaultTypeMap
;
...
...
@@ -470,6 +479,9 @@ class Bucket
* * chunkSizeBytes (integer): The chunk size in bytes. Defaults to the
* bucket's chunk size.
*
* * disableMD5 (boolean): When true, no MD5 sum will be generated for
* the stored file. Defaults to "false".
*
* * metadata (document): User data for the "metadata" field of the files
* collection document.
*
...
...
src/GridFS/WritableStream.php
View file @
f169616c
...
...
@@ -36,9 +36,10 @@ class WritableStream
private
$buffer
=
''
;
private
$chunkOffset
=
0
;
private
$chunkSize
;
private
$disableMD5
;
private
$collectionWrapper
;
private
$ctx
;
private
$file
;
private
$hashCtx
;
private
$isClosed
=
false
;
private
$length
=
0
;
...
...
@@ -56,6 +57,9 @@ class WritableStream
* * chunkSizeBytes (integer): The chunk size in bytes. Defaults to
* 261120 (i.e. 255 KiB).
*
* * disableMD5 (boolean): When true, no MD5 sum will be generated.
* Defaults to "false".
*
* * contentType (string): DEPRECATED content type to be stored with the
* file. This information should now be added to the metadata.
*
...
...
@@ -86,6 +90,10 @@ class WritableStream
throw
new
InvalidArgumentException
(
sprintf
(
'Expected "chunkSizeBytes" option to be >= 1, %d given'
,
$options
[
'chunkSizeBytes'
]));
}
if
(
isset
(
$options
[
'disableMD5'
])
&&
!
is_bool
(
$options
[
'disableMD5'
]))
{
throw
InvalidArgumentException
::
invalidType
(
'"disableMD5" option'
,
$options
[
'disableMD5'
],
'boolean'
);
}
if
(
isset
(
$options
[
'contentType'
])
&&
!
is_string
(
$options
[
'contentType'
]))
{
throw
InvalidArgumentException
::
invalidType
(
'"contentType" option'
,
$options
[
'contentType'
],
'string'
);
}
...
...
@@ -96,7 +104,11 @@ class WritableStream
$this
->
chunkSize
=
$options
[
'chunkSizeBytes'
];
$this
->
collectionWrapper
=
$collectionWrapper
;
$this
->
ctx
=
hash_init
(
'md5'
);
$this
->
disableMD5
=
isset
(
$options
[
'disableMD5'
])
?
$options
[
'disableMD5'
]
:
false
;
if
(
!
$this
->
disableMD5
)
{
$this
->
hashCtx
=
hash_init
(
'md5'
);
}
$this
->
file
=
[
'_id'
=>
$options
[
'_id'
],
...
...
@@ -219,12 +231,14 @@ class WritableStream
private
function
fileCollectionInsert
()
{
$md5
=
hash_final
(
$this
->
ctx
);
$this
->
file
[
'length'
]
=
$this
->
length
;
$this
->
file
[
'md5'
]
=
$md5
;
$this
->
file
[
'uploadDate'
]
=
new
UTCDateTime
;
if
(
!
$this
->
disableMD5
)
{
$md5
=
hash_final
(
$this
->
hashCtx
);
$this
->
file
[
'md5'
]
=
$md5
;
}
try
{
$this
->
collectionWrapper
->
insertFile
(
$this
->
file
);
}
catch
(
DriverRuntimeException
$e
)
{
...
...
@@ -251,7 +265,9 @@ class WritableStream
'data'
=>
new
Binary
(
$data
,
Binary
::
TYPE_GENERIC
),
];
hash_update
(
$this
->
ctx
,
$data
);
if
(
!
$this
->
disableMD5
)
{
hash_update
(
$this
->
hashCtx
,
$data
);
}
try
{
$this
->
collectionWrapper
->
insertChunk
(
$chunk
);
...
...
tests/GridFS/spec-tests/upload.json
View file @
f169616c
...
...
@@ -382,6 +382,85 @@
}
]
}
},
{
"description"
:
"Upload when length is 0 sans MD5"
,
"act"
:
{
"operation"
:
"upload"
,
"arguments"
:
{
"filename"
:
"filename"
,
"source"
:
{
"$hex"
:
""
},
"options"
:
{
"chunkSizeBytes"
:
4
,
"disableMD5"
:
true
}
}
},
"assert"
:
{
"result"
:
"&result"
,
"data"
:
[
{
"insert"
:
"expected.files"
,
"documents"
:
[
{
"_id"
:
"*result"
,
"length"
:
0
,
"chunkSize"
:
4
,
"uploadDate"
:
"*actual"
,
"filename"
:
"filename"
}
]
}
]
}
},
{
"description"
:
"Upload when length is 1 sans MD5"
,
"act"
:
{
"operation"
:
"upload"
,
"arguments"
:
{
"filename"
:
"filename"
,
"source"
:
{
"$hex"
:
"11"
},
"options"
:
{
"chunkSizeBytes"
:
4
,
"disableMD5"
:
true
}
}
},
"assert"
:
{
"result"
:
"&result"
,
"data"
:
[
{
"insert"
:
"expected.files"
,
"documents"
:
[
{
"_id"
:
"*result"
,
"length"
:
1
,
"chunkSize"
:
4
,
"uploadDate"
:
"*actual"
,
"filename"
:
"filename"
}
]
},
{
"insert"
:
"expected.chunks"
,
"documents"
:
[
{
"_id"
:
"*actual"
,
"files_id"
:
"*result"
,
"n"
:
0
,
"data"
:
{
"$hex"
:
"11"
}
}
]
}
]
}
}
]
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment