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
c53cb01a
Commit
c53cb01a
authored
Jun 16, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract DropDatabase operation class
parent
6dc7d316
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
11 deletions
+60
-11
Client.php
src/Client.php
+5
-6
Database.php
src/Database.php
+5
-5
DropDatabase.php
src/Operation/DropDatabase.php
+50
-0
No files found.
src/Client.php
View file @
c53cb01a
...
...
@@ -8,6 +8,7 @@ use MongoDB\Driver\Manager;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Driver\WriteConcern
;
use
MongoDB\Model\DatabaseInfoIterator
;
use
MongoDB\Operation\DropDatabase
;
use
MongoDB\Operation\ListDatabases
;
class
Client
...
...
@@ -36,17 +37,15 @@ class Client
/**
* Drop a database.
*
* @see http://docs.mongodb.org/manual/reference/command/dropDatabase/
* @param string $databaseName
* @return
Cursor
* @return
object Command result document
*/
public
function
dropDatabase
(
$databaseName
)
{
$databaseName
=
(
string
)
$databaseName
;
$command
=
new
Command
(
array
(
'dropDatabase'
=>
1
));
$readPreference
=
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
);
$operation
=
new
DropDatabase
(
$databaseName
);
$server
=
$this
->
manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
));
return
$
this
->
manager
->
executeCommand
(
$databaseName
,
$command
,
$readPreference
);
return
$
operation
->
execute
(
$server
);
}
/**
...
...
src/Database.php
View file @
c53cb01a
...
...
@@ -12,6 +12,7 @@ use MongoDB\Driver\Server;
use
MongoDB\Driver\WriteConcern
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Model\CollectionInfoIterator
;
use
MongoDB\Operation\DropDatabase
;
use
MongoDB\Operation\ListCollections
;
class
Database
...
...
@@ -71,15 +72,14 @@ class Database
/**
* Drop this database.
*
* @see http://docs.mongodb.org/manual/reference/command/dropDatabase/
* @return Cursor
* @return object Command result document
*/
public
function
drop
()
{
$
command
=
new
Command
(
array
(
'dropDatabase'
=>
1
)
);
$
readPreference
=
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
);
$
operation
=
new
DropDatabase
(
$this
->
databaseName
);
$
server
=
$this
->
manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
)
);
return
$
this
->
manager
->
executeCommand
(
$this
->
databaseName
,
$command
,
$readPreference
);
return
$
operation
->
execute
(
$server
);
}
/**
...
...
src/Operation/DropDatabase.php
0 → 100644
View file @
c53cb01a
<?php
namespace
MongoDB\Operation
;
use
MongoDB\Driver\Command
;
use
MongoDB\Driver\Server
;
use
MongoDB\Exception\RuntimeException
;
/**
* Operation for the dropDatabase command.
*
* @api
* @see MongoDB\Client::dropDatabase()
* @see MongoDB\Database::drop()
* @see http://docs.mongodb.org/manual/reference/command/dropDatabase/
*/
class
DropDatabase
implements
Executable
{
private
$databaseName
;
/**
* Constructs a dropDatabase command.
*
* @param string $databaseName Database name
* @param string $collectionName Collection name
*/
public
function
__construct
(
$databaseName
)
{
$this
->
databaseName
=
(
string
)
$databaseName
;
}
/**
* Execute the operation.
*
* @see Executable::execute()
* @param Server $server
* @return object Command result document
*/
public
function
execute
(
Server
$server
)
{
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
new
Command
(
array
(
'dropDatabase'
=>
1
)));
$result
=
current
(
$cursor
->
toArray
());
if
(
empty
(
$result
[
'ok'
]))
{
throw
new
RuntimeException
(
isset
(
$result
[
'errmsg'
])
?
$result
[
'errmsg'
]
:
'Unknown error'
);
}
return
$result
;
}
}
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