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
037ea3b1
Commit
037ea3b1
authored
Feb 26, 2018
by
Katherine Walker
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #503
parents
f6b1b49a
72a19c94
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
4 deletions
+47
-4
Explain.php
src/Operation/Explain.php
+39
-4
ExplainTest.php
tests/Operation/ExplainTest.php
+8
-0
No files found.
src/Operation/Explain.php
View file @
037ea3b1
...
@@ -18,7 +18,9 @@
...
@@ -18,7 +18,9 @@
namespace
MongoDB\Operation
;
namespace
MongoDB\Operation
;
use
MongoDB\Driver\Command
;
use
MongoDB\Driver\Command
;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Driver\Server
;
use
MongoDB\Driver\Server
;
use
MongoDB\Driver\Session
;
use
MongoDB\Exception\UnsupportedException
;
use
MongoDB\Exception\UnsupportedException
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Model\BSONDocument
;
use
MongoDB\Model\BSONDocument
;
...
@@ -49,11 +51,15 @@ class Explain implements Executable
...
@@ -49,11 +51,15 @@ class Explain implements Executable
*
*
* Supported options:
* Supported options:
*
*
* * verbosity (string): The mode in which the explain command will be run.
* * readPreference (MongoDB\Driver\ReadPreference): Read preference.
*
* * session (MongoDB\Driver\Session): Client session.
*
*
* * typeMap (array): Type map for BSON deserialization. This will be used
* * typeMap (array): Type map for BSON deserialization. This will be used
* used for the returned command result document.
* used for the returned command result document.
*
*
* * verbosity (string): The mode in which the explain command will be run.
*
* @param string $databaseName Database name
* @param string $databaseName Database name
* @param Explainable $explainable Operation to explain
* @param Explainable $explainable Operation to explain
* @param array $options Command options
* @param array $options Command options
...
@@ -61,14 +67,22 @@ class Explain implements Executable
...
@@ -61,14 +67,22 @@ class Explain implements Executable
*/
*/
public
function
__construct
(
$databaseName
,
Explainable
$explainable
,
array
$options
=
[])
public
function
__construct
(
$databaseName
,
Explainable
$explainable
,
array
$options
=
[])
{
{
if
(
isset
(
$options
[
'verbosity'
])
&&
!
is_string
(
$options
[
'verbosity'
]))
{
if
(
isset
(
$options
[
'readPreference'
])
&&
!
$options
[
'readPreference'
]
instanceof
ReadPreference
)
{
throw
InvalidArgumentException
::
invalidType
(
'"verbosity" option'
,
$options
[
'verbosity'
],
'string'
);
throw
InvalidArgumentException
::
invalidType
(
'"readPreference" option'
,
$options
[
'readPreference'
],
'MongoDB\Driver\ReadPreference'
);
}
if
(
isset
(
$options
[
'session'
])
&&
!
$options
[
'session'
]
instanceof
Session
)
{
throw
InvalidArgumentException
::
invalidType
(
'"session" option'
,
$options
[
'session'
],
'MongoDB\Driver\Session'
);
}
}
if
(
isset
(
$options
[
'typeMap'
])
&&
!
is_array
(
$options
[
'typeMap'
]))
{
if
(
isset
(
$options
[
'typeMap'
])
&&
!
is_array
(
$options
[
'typeMap'
]))
{
throw
InvalidArgumentException
::
invalidType
(
'"typeMap" option'
,
$options
[
'typeMap'
],
'array'
);
throw
InvalidArgumentException
::
invalidType
(
'"typeMap" option'
,
$options
[
'typeMap'
],
'array'
);
}
}
if
(
isset
(
$options
[
'verbosity'
])
&&
!
is_string
(
$options
[
'verbosity'
]))
{
throw
InvalidArgumentException
::
invalidType
(
'"verbosity" option'
,
$options
[
'verbosity'
],
'string'
);
}
$this
->
databaseName
=
$databaseName
;
$this
->
databaseName
=
$databaseName
;
$this
->
explainable
=
$explainable
;
$this
->
explainable
=
$explainable
;
$this
->
options
=
$options
;
$this
->
options
=
$options
;
...
@@ -94,7 +108,7 @@ class Explain implements Executable
...
@@ -94,7 +108,7 @@ class Explain implements Executable
$cmd
[
'verbosity'
]
=
$this
->
options
[
'verbosity'
];
$cmd
[
'verbosity'
]
=
$this
->
options
[
'verbosity'
];
}
}
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
new
Command
(
$cmd
));
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
new
Command
(
$cmd
)
,
$this
->
createOptions
()
);
if
(
isset
(
$this
->
options
[
'typeMap'
]))
{
if
(
isset
(
$this
->
options
[
'typeMap'
]))
{
$cursor
->
setTypeMap
(
$this
->
options
[
'typeMap'
]);
$cursor
->
setTypeMap
(
$this
->
options
[
'typeMap'
]);
...
@@ -103,6 +117,27 @@ class Explain implements Executable
...
@@ -103,6 +117,27 @@ class Explain implements Executable
return
current
(
$cursor
->
toArray
());
return
current
(
$cursor
->
toArray
());
}
}
/**
* Create options for executing the command.
*
* @see http://php.net/manual/en/mongodb-driver-server.executecommand.php
* @return array
*/
private
function
createOptions
()
{
$options
=
[];
if
(
isset
(
$this
->
options
[
'readPreference'
]))
{
$options
[
'readPreference'
]
=
$this
->
options
[
'readPreference'
];
}
if
(
isset
(
$this
->
options
[
'session'
]))
{
$options
[
'session'
]
=
$this
->
options
[
'session'
];
}
return
$options
;
}
private
function
isFindAndModify
(
$explainable
)
private
function
isFindAndModify
(
$explainable
)
{
{
if
(
$explainable
instanceof
FindAndModify
||
$explainable
instanceof
FindOneAndDelete
||
$explainable
instanceof
FindOneAndReplace
||
$explainable
instanceof
FindOneAndUpdate
)
{
if
(
$explainable
instanceof
FindAndModify
||
$explainable
instanceof
FindOneAndDelete
||
$explainable
instanceof
FindOneAndReplace
||
$explainable
instanceof
FindOneAndUpdate
)
{
...
...
tests/Operation/ExplainTest.php
View file @
037ea3b1
...
@@ -22,6 +22,14 @@ class ExplainTest extends TestCase
...
@@ -22,6 +22,14 @@ class ExplainTest extends TestCase
{
{
$options
=
[];
$options
=
[];
foreach
(
$this
->
getInvalidReadPreferenceValues
()
as
$value
)
{
$options
[][]
=
[
'readPreference'
=>
$value
];
}
foreach
(
$this
->
getInvalidSessionValues
()
as
$value
)
{
$options
[][]
=
[
'session'
=>
$value
];
}
foreach
(
$this
->
getInvalidStringValues
()
as
$value
)
{
foreach
(
$this
->
getInvalidStringValues
()
as
$value
)
{
$options
[][]
=
[
'verbosity'
=>
$value
];
$options
[][]
=
[
'verbosity'
=>
$value
];
}
}
...
...
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