diff --git a/src/Client.php b/src/Client.php index 4031ed11e..be0d5b35a 100644 --- a/src/Client.php +++ b/src/Client.php @@ -14,8 +14,6 @@ class Client { private $manager; - private $readPreference; - private $writeConcern; /** * Constructs a new Client instance. @@ -77,9 +75,8 @@ public function listDatabases(array $options = array()) public function selectCollection($databaseName, $collectionName, WriteConcern $writeConcern = null, ReadPreference $readPreference = null) { $namespace = $databaseName . '.' . $collectionName; - // TODO: inherit from Manager options once PHPC-196 is implemented - $writeConcern = $writeConcern ?: $this->writeConcern; - $readPreference = $readPreference ?: $this->readPreference; + $writeConcern = $writeConcern ?: $this->manager->getWriteConcern(); + $readPreference = $readPreference ?: $this->manager->getReadPreference(); return new Collection($this->manager, $namespace, $writeConcern, $readPreference); } @@ -97,9 +94,8 @@ public function selectCollection($databaseName, $collectionName, WriteConcern $w */ public function selectDatabase($databaseName, WriteConcern $writeConcern = null, ReadPreference $readPreference = null) { - // TODO: inherit from Manager options once PHPC-196 is implemented - $writeConcern = $writeConcern ?: $this->writeConcern; - $readPreference = $readPreference ?: $this->readPreference; + $writeConcern = $writeConcern ?: $this->manager->getWriteConcern(); + $readPreference = $readPreference ?: $this->manager->getReadPreference(); return new Database($this->manager, $databaseName, $writeConcern, $readPreference); } diff --git a/src/Operation/Aggregate.php b/src/Operation/Aggregate.php index 6e12d05d1..1a7ccdf50 100644 --- a/src/Operation/Aggregate.php +++ b/src/Operation/Aggregate.php @@ -122,12 +122,8 @@ public function execute(Server $server) return $cursor; } - $cursor->setTypeMap(array('document' => 'stdClass')); $result = current($cursor->toArray()); - // TODO: Remove this once PHPC-318 is implemented - is_array($result) and $result = (object) $result; - if (empty($result->ok)) { throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error'); } diff --git a/src/Operation/Count.php b/src/Operation/Count.php index fe43eb6de..b50b46e0e 100644 --- a/src/Operation/Count.php +++ b/src/Operation/Count.php @@ -85,19 +85,18 @@ public function __construct($databaseName, $collectionName, array $filter = arra public function execute(Server $server) { $cursor = $server->executeCommand($this->databaseName, $this->createCommand()); - $cursor->setTypeMap(array('root' => 'array', 'document' => 'array')); $result = current($cursor->toArray()); - if (empty($result['ok'])) { - throw new RuntimeException(isset($result['errmsg']) ? $result['errmsg'] : 'Unknown error'); + if (empty($result->ok)) { + throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error'); } // Older server versions may return a float - if ( ! isset($result['n']) || ! (is_integer($result['n']) || is_float($result['n']))) { - throw new UnexpectedValueException('count command did not return an "n" value'); + if ( ! isset($result->n) || ! (is_integer($result->n) || is_float($result->n))) { + throw new UnexpectedValueException('count command did not return a numeric "n" value'); } - return (integer) $result['n']; + return (integer) $result->n; } /** diff --git a/src/Operation/CreateCollection.php b/src/Operation/CreateCollection.php index 562015b1a..ad69e29fa 100644 --- a/src/Operation/CreateCollection.php +++ b/src/Operation/CreateCollection.php @@ -102,12 +102,8 @@ public function __construct($databaseName, $collectionName, array $options = arr public function execute(Server $server) { $cursor = $server->executeCommand($this->databaseName, $this->createCommand()); - $cursor->setTypeMap(array('document' => 'stdClass')); $result = current($cursor->toArray()); - // TODO: Remove this once PHPC-318 is implemented - is_array($result) and $result = (object) $result; - if (empty($result->ok)) { throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error'); } diff --git a/src/Operation/CreateIndexes.php b/src/Operation/CreateIndexes.php index 765ce477d..2fa46f92f 100644 --- a/src/Operation/CreateIndexes.php +++ b/src/Operation/CreateIndexes.php @@ -91,11 +91,10 @@ private function executeCommand(Server $server) )); $cursor = $server->executeCommand($this->databaseName, $command); - $cursor->setTypeMap(array('root' => 'array', 'document' => 'array')); $result = current($cursor->toArray()); - if (empty($result['ok'])) { - throw new RuntimeException(isset($result['errmsg']) ? $result['errmsg'] : 'Unknown error'); + if (empty($result->ok)) { + throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error'); } } diff --git a/src/Operation/Distinct.php b/src/Operation/Distinct.php index fa4c9bf42..2ed2dfecf 100644 --- a/src/Operation/Distinct.php +++ b/src/Operation/Distinct.php @@ -62,12 +62,8 @@ public function __construct($databaseName, $collectionName, $fieldName, array $f public function execute(Server $server) { $cursor = $server->executeCommand($this->databaseName, $this->createCommand()); - $cursor->setTypeMap(array('document' => 'stdClass')); $result = current($cursor->toArray()); - // TODO: Remove this once PHPC-318 is implemented - is_array($result) and $result = (object) $result; - if (empty($result->ok)) { throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error'); } diff --git a/src/Operation/DropCollection.php b/src/Operation/DropCollection.php index 2cd3f5330..7323403b9 100644 --- a/src/Operation/DropCollection.php +++ b/src/Operation/DropCollection.php @@ -41,12 +41,8 @@ public function __construct($databaseName, $collectionName) public function execute(Server $server) { $cursor = $server->executeCommand($this->databaseName, new Command(array('drop' => $this->collectionName))); - $cursor->setTypeMap(array('document' => 'stdClass')); $result = current($cursor->toArray()); - // TODO: Remove this once PHPC-318 is implemented - is_array($result) and $result = (object) $result; - if (empty($result->ok)) { throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error'); } diff --git a/src/Operation/DropDatabase.php b/src/Operation/DropDatabase.php index 7c22fc08c..199d485af 100644 --- a/src/Operation/DropDatabase.php +++ b/src/Operation/DropDatabase.php @@ -39,12 +39,8 @@ public function __construct($databaseName) public function execute(Server $server) { $cursor = $server->executeCommand($this->databaseName, new Command(array('dropDatabase' => 1))); - $cursor->setTypeMap(array('document' => 'stdClass')); $result = current($cursor->toArray()); - // TODO: Remove this once PHPC-318 is implemented - is_array($result) and $result = (object) $result; - if (empty($result->ok)) { throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error'); } diff --git a/src/Operation/DropIndexes.php b/src/Operation/DropIndexes.php index c79b21cdc..8db7a54be 100644 --- a/src/Operation/DropIndexes.php +++ b/src/Operation/DropIndexes.php @@ -56,12 +56,8 @@ public function execute(Server $server) ); $cursor = $server->executeCommand($this->databaseName, new Command($cmd)); - $cursor->setTypeMap(array('document' => 'stdClass')); $result = current($cursor->toArray()); - // TODO: Remove this once PHPC-318 is implemented - is_array($result) and $result = (object) $result; - if (empty($result->ok)) { throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error'); } diff --git a/src/Operation/FindAndModify.php b/src/Operation/FindAndModify.php index bf0a76bd7..57e61eef6 100644 --- a/src/Operation/FindAndModify.php +++ b/src/Operation/FindAndModify.php @@ -118,12 +118,8 @@ public function __construct($databaseName, $collectionName, array $options) public function execute(Server $server) { $cursor = $server->executeCommand($this->databaseName, $this->createCommand()); - $cursor->setTypeMap(array('document' => 'stdClass')); $result = current($cursor->toArray()); - // TODO: Remove this once PHPC-318 is implemented - is_array($result) and $result = (object) $result; - if (empty($result->ok)) { throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error'); }