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
cc09f79e
Commit
cc09f79e
authored
Sep 12, 2016
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #224
parents
0195906b
748c14f4
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
80 additions
and
0 deletions
+80
-0
Database.php
src/Database.php
+19
-0
Bucket.php
src/GridFS/Bucket.php
+12
-0
DatabaseFunctionalTest.php
tests/Database/DatabaseFunctionalTest.php
+49
-0
No files found.
src/Database.php
View file @
cc09f79e
...
...
@@ -9,6 +9,7 @@ use MongoDB\Driver\ReadConcern;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Driver\WriteConcern
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\GridFS\Bucket
;
use
MongoDB\Model\CollectionInfoIterator
;
use
MongoDB\Operation\CreateCollection
;
use
MongoDB\Operation\DatabaseCommand
;
...
...
@@ -262,6 +263,24 @@ class Database
return
new
Collection
(
$this
->
manager
,
$this
->
databaseName
,
$collectionName
,
$options
);
}
/**
* Select a GridFS bucket within this database.
*
* @see Bucket::__construct() for supported options
* @param array $options Bucket constructor options
* @return Bucket
*/
public
function
selectGridFSBucket
(
array
$options
=
[])
{
$options
+=
[
'readConcern'
=>
$this
->
readConcern
,
'readPreference'
=>
$this
->
readPreference
,
'writeConcern'
=>
$this
->
writeConcern
,
];
return
new
Bucket
(
$this
->
manager
,
$this
->
databaseName
,
$options
);
}
/**
* Get a clone of this database with different options.
*
...
...
src/GridFS/Bucket.php
View file @
cc09f79e
...
...
@@ -27,8 +27,12 @@ class Bucket
private
$collectionWrapper
;
private
$databaseName
;
private
$manager
;
private
$bucketName
;
private
$chunkSizeBytes
;
private
$readConcern
;
private
$readPreference
;
private
$writeConcern
;
/**
* Constructs a GridFS bucket.
...
...
@@ -79,9 +83,13 @@ class Bucket
throw
InvalidArgumentException
::
invalidType
(
'"writeConcern" option'
,
$options
[
'writeConcern'
],
'MongoDB\Driver\WriteConcern'
);
}
$this
->
manager
=
$manager
;
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
bucketName
=
$options
[
'bucketName'
];
$this
->
chunkSizeBytes
=
$options
[
'chunkSizeBytes'
];
$this
->
readConcern
=
isset
(
$options
[
'readConcern'
])
?
$options
[
'readConcern'
]
:
$this
->
manager
->
getReadConcern
();
$this
->
readPreference
=
isset
(
$options
[
'readPreference'
])
?
$options
[
'readPreference'
]
:
$this
->
manager
->
getReadPreference
();
$this
->
writeConcern
=
isset
(
$options
[
'writeConcern'
])
?
$options
[
'writeConcern'
]
:
$this
->
manager
->
getWriteConcern
();
$collectionOptions
=
array_intersect_key
(
$options
,
[
'readConcern'
=>
1
,
'readPreference'
=>
1
,
'writeConcern'
=>
1
]);
...
...
@@ -100,7 +108,11 @@ class Bucket
return
[
'bucketName'
=>
$this
->
bucketName
,
'databaseName'
=>
$this
->
databaseName
,
'manager'
=>
$this
->
manager
,
'chunkSizeBytes'
=>
$this
->
chunkSizeBytes
,
'readConcern'
=>
$this
->
readConcern
,
'readPreference'
=>
$this
->
readPreference
,
'writeConcern'
=>
$this
->
writeConcern
,
];
}
...
...
tests/Database/DatabaseFunctionalTest.php
View file @
cc09f79e
...
...
@@ -190,6 +190,55 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
}
public
function
testSelectGridFSBucketInheritsOptions
()
{
$databaseOptions
=
[
'readConcern'
=>
new
ReadConcern
(
ReadConcern
::
LOCAL
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
];
$database
=
new
Database
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$databaseOptions
);
$bucket
=
$database
->
selectGridFSBucket
();
$debug
=
$bucket
->
__debugInfo
();
$this
->
assertSame
(
$this
->
manager
,
$debug
[
'manager'
]);
$this
->
assertSame
(
$this
->
getDatabaseName
(),
$debug
[
'databaseName'
]);
$this
->
assertSame
(
'fs'
,
$debug
[
'bucketName'
]);
$this
->
assertSame
(
261120
,
$debug
[
'chunkSizeBytes'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadConcern'
,
$debug
[
'readConcern'
]);
$this
->
assertSame
(
ReadConcern
::
LOCAL
,
$debug
[
'readConcern'
]
->
getLevel
());
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadPreference'
,
$debug
[
'readPreference'
]);
$this
->
assertSame
(
ReadPreference
::
RP_SECONDARY_PREFERRED
,
$debug
[
'readPreference'
]
->
getMode
());
$this
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
}
public
function
testSelectGridFSBucketPassesOptions
()
{
$bucketOptions
=
[
'bucketName'
=>
'custom_fs'
,
'chunkSizeBytes'
=>
8192
,
'readConcern'
=>
new
ReadConcern
(
ReadConcern
::
LOCAL
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
];
$database
=
new
Database
(
$this
->
manager
,
$this
->
getDatabaseName
());
$bucket
=
$database
->
selectGridFSBucket
(
$bucketOptions
);
$debug
=
$bucket
->
__debugInfo
();
$this
->
assertSame
(
$this
->
getDatabaseName
(),
$debug
[
'databaseName'
]);
$this
->
assertSame
(
'custom_fs'
,
$debug
[
'bucketName'
]);
$this
->
assertSame
(
8192
,
$debug
[
'chunkSizeBytes'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadConcern'
,
$debug
[
'readConcern'
]);
$this
->
assertSame
(
ReadConcern
::
LOCAL
,
$debug
[
'readConcern'
]
->
getLevel
());
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadPreference'
,
$debug
[
'readPreference'
]);
$this
->
assertSame
(
ReadPreference
::
RP_SECONDARY_PREFERRED
,
$debug
[
'readPreference'
]
->
getMode
());
$this
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
}
public
function
testWithOptionsInheritsOptions
()
{
$databaseOptions
=
[
...
...
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