Skip to content

Fixing a few more issues that I ran into regarding documents vs arrays (and function non-autoloading) #1

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

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5f30f51
Split UnexpectedTypeException for logic and runtime errors
jmikola May 7, 2015
660face
Create functions.php file for utility functions
jmikola Jun 15, 2015
35a984b
Executable interface for operations
jmikola Jun 10, 2015
a5752ad
Extract Collection::aggregate() to an operation class
jmikola Jun 10, 2015
2c95230
Extract Collection::distinct() to an operation class
jmikola Jun 10, 2015
1c578e3
Extract Collection::createIndexes() to an operation class
jmikola Jun 10, 2015
556cfd2
Extract Collection::count() to an operation class
jmikola Jun 11, 2015
bf4c450
Extract Collection findAndModify methods to operation classes
jmikola Jun 15, 2015
17f03f6
Return documents as objects from Collection findAndModify methods
jmikola Jun 15, 2015
cd89712
Replace private methods with generate_index_name() function
jmikola Jun 15, 2015
34670b7
Extract Client::listDatabases() to an operation class
jmikola Jun 16, 2015
49b54df
Extract Database::listCollections() to an operation class
jmikola Jun 16, 2015
eee33ce
Extract Collection::listIndexes() to an operation class
jmikola Jun 16, 2015
d9b34ae
Extract DropDatabase operation class
jmikola Jun 16, 2015
4857b5e
Extra DropCollection operation class
jmikola Jun 16, 2015
ea68778
Extract Database::createCollection() to an operation class
jmikola Jun 16, 2015
582df90
Extract DropIndexes operation class
jmikola Jun 16, 2015
e8e4aa5
assertCommandSucceeded() now accepts a result document
jmikola Jun 16, 2015
f9dab58
FeatureDetection utility class is obsolete
jmikola Jun 16, 2015
3cb9adc
Remove unused Collection constants and methods
jmikola Jun 16, 2015
443bbbf
Don't assume document PHP type mapping in FunctionalTestCase
jmikola Jun 17, 2015
31299e9
Older servers may return count "n" as a float
jmikola Jun 17, 2015
6bdecdb
Relax assertion in AggregateFunctionalTest
jmikola Jun 17, 2015
d26149b
Aggregate should check server support before returning a cursor
jmikola Jun 17, 2015
3ed4deb
Use type map to force arrays instead of objects.
derickr Jun 18, 2015
0fa1041
Require the non-autoloaded functions
derickr Jun 18, 2015
cf94ead
Compare all arrays of documents by setting the typemap for documents …
derickr Jun 18, 2015
bbc37a5
Because the typemap says 'document as array', we now need to change t…
derickr Jun 18, 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