Skip to content

Commit 60931d8

Browse files
committed
Merge pull request #13
2 parents 64c4014 + cab405d commit 60931d8

32 files changed

+1926
-767
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"ext-mongodb": ">=0.6.0"
1414
},
1515
"autoload": {
16-
"psr-4": { "MongoDB\\": "src/" }
16+
"psr-4": { "MongoDB\\": "src/" },
17+
"files": [ "src/functions.php" ]
1718
},
1819
"extra": {
1920
"branch-alias": {

src/Client.php

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
use MongoDB\Driver\Manager;
88
use MongoDB\Driver\ReadPreference;
99
use MongoDB\Driver\WriteConcern;
10-
use MongoDB\Exception\UnexpectedValueException;
1110
use MongoDB\Model\DatabaseInfoIterator;
12-
use MongoDB\Model\DatabaseInfoLegacyIterator;
11+
use MongoDB\Operation\DropDatabase;
12+
use MongoDB\Operation\ListDatabases;
1313

1414
class Client
1515
{
@@ -37,45 +37,29 @@ public function __construct($uri, array $options = array(), array $driverOptions
3737
/**
3838
* Drop a database.
3939
*
40-
* @see http://docs.mongodb.org/manual/reference/command/dropDatabase/
4140
* @param string $databaseName
42-
* @return Cursor
41+
* @return object Command result document
4342
*/
4443
public function dropDatabase($databaseName)
4544
{
46-
$databaseName = (string) $databaseName;
47-
$command = new Command(array('dropDatabase' => 1));
48-
$readPreference = new ReadPreference(ReadPreference::RP_PRIMARY);
45+
$operation = new DropDatabase($databaseName);
46+
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
4947

50-
return $this->manager->executeCommand($databaseName, $command, $readPreference);
48+
return $operation->execute($server);
5149
}
5250

5351
/**
5452
* List databases.
5553
*
56-
* @see http://docs.mongodb.org/manual/reference/command/listDatabases/
54+
* @see ListDatabases::__construct() for supported options
5755
* @return DatabaseInfoIterator
58-
* @throws UnexpectedValueException if the command result is malformed
5956
*/
60-
public function listDatabases()
57+
public function listDatabases(array $options = array())
6158
{
62-
$command = new Command(array('listDatabases' => 1));
59+
$operation = new ListDatabases($options);
60+
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
6361

64-
$cursor = $this->manager->executeCommand('admin', $command);
65-
$cursor->setTypeMap(array('document' => 'array'));
66-
$result = current($cursor->toArray());
67-
68-
if ( ! isset($result['databases']) || ! is_array($result['databases'])) {
69-
throw new UnexpectedValueException('listDatabases command did not return a "databases" array');
70-
}
71-
72-
/* Return an Iterator instead of an array in case listDatabases is
73-
* eventually changed to return a command cursor, like the collection
74-
* and index enumeration commands. This makes the "totalSize" command
75-
* field inaccessible, but users can manually invoke the command if they
76-
* need that value.
77-
*/
78-
return new DatabaseInfoLegacyIterator($result['databases']);
62+
return $operation->execute($server);
7963
}
8064

8165
/**

0 commit comments

Comments
 (0)