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
74989eb7
Commit
74989eb7
authored
Mar 20, 2016
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #143
parents
03e9decb
4cd5342e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
19 additions
and
20 deletions
+19
-20
Bucket.php
src/GridFS/Bucket.php
+5
-5
GridFSCollectionsWrapper.php
src/GridFS/GridFSCollectionsWrapper.php
+0
-1
GridFSUpload.php
src/GridFS/GridFSUpload.php
+6
-6
BucketFunctionalTest.php
tests/GridFS/BucketFunctionalTest.php
+1
-1
GridFSStreamTest.php
tests/GridFS/GridFSStreamTest.php
+7
-7
No files found.
src/GridFS/Bucket.php
View file @
74989eb7
...
...
@@ -6,7 +6,7 @@ use MongoDB\BSON\ObjectId;
use
MongoDB\Driver\Cursor
;
use
MongoDB\Driver\Manager
;
use
MongoDB\Exception\GridFSFileNotFoundException
;
use
MongoDB\Exception\InvalidArgument
Type
Exception
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Operation\Find
;
/**
...
...
@@ -51,19 +51,19 @@ class Bucket
];
if
(
isset
(
$options
[
'bucketName'
])
&&
!
is_string
(
$options
[
'bucketName'
]))
{
throw
new
InvalidArgumentTypeException
(
'"bucketName" option'
,
$options
[
'bucketName'
],
'string'
);
throw
InvalidArgumentException
::
invalidType
(
'"bucketName" option'
,
$options
[
'bucketName'
],
'string'
);
}
if
(
isset
(
$options
[
'chunkSizeBytes'
])
&&
!
is_integer
(
$options
[
'chunkSizeBytes'
]))
{
throw
new
InvalidArgumentTypeException
(
'"chunkSizeBytes" option'
,
$options
[
'chunkSizeBytes'
],
'integer'
);
throw
InvalidArgumentException
::
invalidType
(
'"chunkSizeBytes" option'
,
$options
[
'chunkSizeBytes'
],
'integer'
);
}
if
(
isset
(
$options
[
'readPreference'
])
&&
!
$options
[
'readPreference'
]
instanceof
ReadPreference
)
{
throw
new
InvalidArgumentTypeException
(
'"readPreference" option'
,
$options
[
'readPreference'
],
'MongoDB\Driver\ReadPreference'
);
throw
InvalidArgumentException
::
invalidType
(
'"readPreference" option'
,
$options
[
'readPreference'
],
'MongoDB\Driver\ReadPreference'
);
}
if
(
isset
(
$options
[
'writeConcern'
])
&&
!
$options
[
'writeConcern'
]
instanceof
WriteConcern
)
{
throw
new
InvalidArgumentTypeException
(
'"writeConcern" option'
,
$options
[
'writeConcern'
],
'MongoDB\Driver\WriteConcern'
);
throw
InvalidArgumentException
::
invalidType
(
'"writeConcern" option'
,
$options
[
'writeConcern'
],
'MongoDB\Driver\WriteConcern'
);
}
$this
->
databaseName
=
(
string
)
$databaseName
;
...
...
src/GridFS/GridFSCollectionsWrapper.php
View file @
74989eb7
...
...
@@ -6,7 +6,6 @@ use MongoDB\Collection;
use
MongoDB\Driver\Manager
;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Driver\WriteConcern
;
use
MongoDB\Exception\InvalidArgumentTypeException
;
/**
* GridFSCollectionsWrapper abstracts the GridFS files and chunks collections.
...
...
src/GridFS/GridFSUpload.php
View file @
74989eb7
...
...
@@ -6,7 +6,7 @@ use MongoDB\BSON\Binary;
use
MongoDB\BSON\ObjectId
;
use
MongoDB\BSON\UTCDateTime
;
use
MongoDB\Driver\Exception\Exception
;
use
MongoDB\Exception\InvalidArgument
Type
Exception
;
use
MongoDB\Exception\InvalidArgumentException
;
/**
* GridFSUpload abstracts the process of writing a GridFS file.
...
...
@@ -47,22 +47,22 @@ class GridFSUpload
* @param GridFSCollectionsWrapper $collectionsWrapper GridFS collections wrapper
* @param string $filename File name
* @param array $options Upload options
* @throws InvalidArgument
Type
Exception
* @throws InvalidArgumentException
*/
public
function
__construct
(
GridFSCollectionsWrapper
$collectionsWrapper
,
$filename
,
array
$options
=
[])
{
$options
+=
[
'chunkSizeBytes'
=>
261120
];
if
(
isset
(
$options
[
'aliases'
])
&&
!
\MongoDB\is_string_array
(
$options
[
'aliases'
]))
{
throw
new
InvalidArgumentTypeException
(
'"aliases" option'
,
$options
[
'aliases'
],
'array of strings'
);
throw
InvalidArgumentException
::
invalidType
(
'"aliases" option'
,
$options
[
'aliases'
],
'array of strings'
);
}
if
(
isset
(
$options
[
'contentType'
])
&&
!
is_string
(
$options
[
'contentType'
]))
{
throw
new
InvalidArgumentTypeException
(
'"contentType" option'
,
$options
[
'contentType'
],
'string'
);
throw
InvalidArgumentException
::
invalidType
(
'"contentType" option'
,
$options
[
'contentType'
],
'string'
);
}
if
(
isset
(
$options
[
'metadata'
])
&&
!
is_array
(
$options
[
'metadata'
])
&&
!
is_object
(
$options
[
'metadata'
]))
{
throw
new
InvalidArgumentTypeException
(
'"metadata" option'
,
$options
[
'metadata'
],
'array or object'
);
throw
InvalidArgumentException
::
invalidType
(
'"metadata" option'
,
$options
[
'metadata'
],
'array or object'
);
}
$this
->
chunkSize
=
$options
[
'chunkSizeBytes'
];
...
...
@@ -175,7 +175,7 @@ class GridFSUpload
public
function
uploadFromStream
(
$source
)
{
if
(
!
is_resource
(
$source
)
||
get_resource_type
(
$source
)
!=
"stream"
)
{
throw
new
InvalidArgumentTypeException
(
'$stream
'
,
$source
,
'resource'
);
throw
InvalidArgumentException
::
invalidType
(
'$source
'
,
$source
,
'resource'
);
}
$streamMetadata
=
stream_get_meta_data
(
$source
);
...
...
tests/GridFS/BucketFunctionalTest.php
View file @
74989eb7
...
...
@@ -11,7 +11,7 @@ class BucketFunctionalTest extends FunctionalTestCase
{
/**
* @expectedException MongoDB\Exception\InvalidArgument
Type
Exception
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions
*/
public
function
testConstructorOptionTypeChecks
(
array
$options
)
...
...
tests/GridFS/GridFSStreamTest.php
View file @
74989eb7
...
...
@@ -20,7 +20,7 @@ class GridFSStreamTest extends FunctionalTestCase
$this
->
assertEquals
(
1
,
$this
->
collectionsWrapper
->
getFilesCollection
()
->
count
());
$this
->
assertEquals
(
1
,
$this
->
collectionsWrapper
->
getChunksCollection
()
->
count
());
$file
=
$this
->
collectionsWrapper
->
getFilesCollection
()
->
findOne
([
"_id"
=>
$id
]);
$file
=
$this
->
collectionsWrapper
->
getFilesCollection
()
->
findOne
([
"_id"
=>
$id
]
,
[
'typeMap'
=>
[
'root'
=>
'stdClass'
]]
);
$download
=
new
\MongoDB\GridFS\GridFSDownload
(
$this
->
collectionsWrapper
,
$file
);
$stream
=
fopen
(
'php://temp'
,
'w+'
);
...
...
@@ -46,7 +46,7 @@ class GridFSStreamTest extends FunctionalTestCase
$this
->
assertEquals
(
2
,
$this
->
collectionsWrapper
->
getFilesCollection
()
->
count
());
$this
->
assertEquals
(
1
,
$this
->
collectionsWrapper
->
getChunksCollection
()
->
count
());
$file
=
$this
->
collectionsWrapper
->
getFilesCollection
()
->
findOne
([
"_id"
=>
$id
]);
$file
=
$this
->
collectionsWrapper
->
getFilesCollection
()
->
findOne
([
"_id"
=>
$id
]
,
[
'typeMap'
=>
[
'root'
=>
'stdClass'
]]
);
$download
=
new
\MongoDB\GridFS\GridFSDownload
(
$this
->
collectionsWrapper
,
$file
);
$stream
=
fopen
(
'php://temp'
,
'w+'
);
$download
->
downloadToStream
(
$stream
);
...
...
@@ -100,7 +100,7 @@ class GridFSStreamTest extends FunctionalTestCase
$upload
=
new
\MongoDB\GridFS\GridFSUpload
(
$this
->
collectionsWrapper
,
"test"
);
$upload
->
close
();
$file
=
$this
->
collectionsWrapper
->
getFilesCollection
()
->
findOne
([
"_id"
=>
$upload
->
getId
()]);
$file
=
$this
->
collectionsWrapper
->
getFilesCollection
()
->
findOne
([
"_id"
=>
$upload
->
getId
()]
,
[
'typeMap'
=>
[
'root'
=>
'stdClass'
]]
);
$download
=
new
\MongoDB\GridFS\GridFSDownload
(
$this
->
collectionsWrapper
,
$file
);
$download
->
close
();
...
...
@@ -124,7 +124,7 @@ class GridFSStreamTest extends FunctionalTestCase
$upload
->
insertChunks
(
"hello world"
);
$upload
->
close
();
$file
=
$this
->
collectionsWrapper
->
getFilesCollection
()
->
findOne
([
"_id"
=>
$upload
->
getId
()]);
$file
=
$this
->
collectionsWrapper
->
getFilesCollection
()
->
findOne
([
"_id"
=>
$upload
->
getId
()]
,
[
'typeMap'
=>
[
'root'
=>
'stdClass'
]]
);
$download
=
new
\MongoDB\GridFS\GridFSDownload
(
$this
->
collectionsWrapper
,
$file
);
$this
->
assertEquals
(
"test"
,
$download
->
getFile
()
->
filename
);
...
...
@@ -185,7 +185,7 @@ class GridFSStreamTest extends FunctionalTestCase
$upload
=
new
\MongoDB\GridFS\GridFSUpload
(
$this
->
collectionsWrapper
,
"test"
,
[
"chunkSizeBytes"
=>
3
]);
$upload
->
insertChunks
(
"hello world"
);
$upload
->
close
();
$file
=
$this
->
collectionsWrapper
->
getFilesCollection
()
->
findOne
([
"_id"
=>
$upload
->
getId
()]);
$file
=
$this
->
collectionsWrapper
->
getFilesCollection
()
->
findOne
([
"_id"
=>
$upload
->
getId
()]
,
[
'typeMap'
=>
[
'root'
=>
'stdClass'
]]
);
$download
=
new
\MongoDB\GridFS\GridFSDownload
(
$this
->
collectionsWrapper
,
$file
);
$this
->
assertEquals
(
"he"
,
$download
->
downloadNumBytes
(
2
));
$this
->
assertEquals
(
"ll"
,
$download
->
downloadNumBytes
(
2
));
...
...
@@ -205,7 +205,7 @@ class GridFSStreamTest extends FunctionalTestCase
$upload
=
new
\MongoDB\GridFS\GridFSUpload
(
$this
->
collectionsWrapper
,
"test"
,
[
"chunkSizeBytes"
=>
rand
(
1
,
5
)]);
$upload
->
insertChunks
(
$data
);
$upload
->
close
();
$file
=
$this
->
collectionsWrapper
->
getFilesCollection
()
->
findOne
([
"_id"
=>
$upload
->
getId
()]);
$file
=
$this
->
collectionsWrapper
->
getFilesCollection
()
->
findOne
([
"_id"
=>
$upload
->
getId
()]
,
[
'typeMap'
=>
[
'root'
=>
'stdClass'
]]
);
$download
=
new
\MongoDB\GridFS\GridFSDownload
(
$this
->
collectionsWrapper
,
$file
);
$readPos
=
0
;
...
...
@@ -222,7 +222,7 @@ class GridFSStreamTest extends FunctionalTestCase
$download
->
close
();
}
/**
* @expectedException \MongoDB\Exception\InvalidArgument
Type
Exception
* @expectedException \MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidUploadConstructorOptions
*/
public
function
testUploadConstructorOptionTypeChecks
(
array
$options
)
...
...
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