Skip to content

PHPLIB-104: Operation classes for some commands #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Jun 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9c108d5
Split UnexpectedTypeException for logic and runtime errors
jmikola May 7, 2015
d77b7fc
Create functions.php file for utility functions
jmikola Jun 15, 2015
a079417
Executable interface for operations
jmikola Jun 10, 2015
7973b38
Extract Collection::aggregate() to an operation class
jmikola Jun 10, 2015
9746ccd
Extract Collection::distinct() to an operation class
jmikola Jun 10, 2015
5b7bb9a
Extract Collection::createIndexes() to an operation class
jmikola Jun 10, 2015
e36a304
Extract Collection::count() to an operation class
jmikola Jun 11, 2015
02e651c
Extract Collection findAndModify methods to operation classes
jmikola Jun 15, 2015
3028dfd
Return documents as objects from Collection findAndModify methods
jmikola Jun 15, 2015
bc65629
Replace private methods with generate_index_name() function
jmikola Jun 15, 2015
1269542
Extract Client::listDatabases() to an operation class
jmikola Jun 16, 2015
99650bb
Extract Database::listCollections() to an operation class
jmikola Jun 16, 2015
6dc7d31
Extract Collection::listIndexes() to an operation class
jmikola Jun 16, 2015
c53cb01
Extract DropDatabase operation class
jmikola Jun 16, 2015
d2fe8b3
Extra DropCollection operation class
jmikola Jun 16, 2015
3c28b7d
Extract Database::createCollection() to an operation class
jmikola Jun 16, 2015
d070cf8
Extract DropIndexes operation class
jmikola Jun 16, 2015
c257a95
assertCommandSucceeded() now accepts a result document
jmikola Jun 16, 2015
9b4d0ef
FeatureDetection utility class is obsolete
jmikola Jun 16, 2015
c0f2c16
Remove unused Collection constants and methods
jmikola Jun 16, 2015
c5a0964
Don't assume document PHP type mapping in FunctionalTestCase
jmikola Jun 17, 2015
fb7cb1b
Older servers may return count "n" as a float
jmikola Jun 17, 2015
26078fe
Relax assertion in AggregateFunctionalTest
jmikola Jun 17, 2015
cab405d
Aggregate should check server support before returning a cursor
jmikola Jun 17, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"ext-mongodb": ">=0.6.0"
},
"autoload": {
"psr-4": { "MongoDB\\": "src/" }
"psr-4": { "MongoDB\\": "src/" },
"files": [ "src/functions.php" ]
},
"extra": {
"branch-alias": {
Expand Down
38 changes: 11 additions & 27 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
use MongoDB\Driver\Manager;
use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\UnexpectedValueException;
use MongoDB\Model\DatabaseInfoIterator;
use MongoDB\Model\DatabaseInfoLegacyIterator;
use MongoDB\Operation\DropDatabase;
use MongoDB\Operation\ListDatabases;

class Client
{
Expand Down Expand Up @@ -37,45 +37,29 @@ public function __construct($uri, array $options = array(), array $driverOptions
/**
* 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);
}

/**
* List databases.
*
* @see http://docs.mongodb.org/manual/reference/command/listDatabases/
* @see ListDatabases::__construct() for supported options
* @return DatabaseInfoIterator
* @throws UnexpectedValueException if the command result is malformed
*/
public function listDatabases()
public function listDatabases(array $options = array())
{
$command = new Command(array('listDatabases' => 1));
$operation = new ListDatabases($options);
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));

$cursor = $this->manager->executeCommand('admin', $command);
$cursor->setTypeMap(array('document' => 'array'));
$result = current($cursor->toArray());

if ( ! isset($result['databases']) || ! is_array($result['databases'])) {
throw new UnexpectedValueException('listDatabases command did not return a "databases" array');
}

/* Return an Iterator instead of an array in case listDatabases is
* eventually changed to return a command cursor, like the collection
* and index enumeration commands. This makes the "totalSize" command
* field inaccessible, but users can manually invoke the command if they
* need that value.
*/
return new DatabaseInfoLegacyIterator($result['databases']);
return $operation->execute($server);
}

/**
Expand Down
Loading