Skip to content

Commit 694c211

Browse files
committed
Merge pull request mongodb#27
2 parents ced7145 + e223a19 commit 694c211

File tree

10 files changed

+11
-45
lines changed

10 files changed

+11
-45
lines changed

src/Client.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
class Client
1515
{
1616
private $manager;
17-
private $readPreference;
18-
private $writeConcern;
1917

2018
/**
2119
* Constructs a new Client instance.
@@ -77,9 +75,8 @@ public function listDatabases(array $options = array())
7775
public function selectCollection($databaseName, $collectionName, WriteConcern $writeConcern = null, ReadPreference $readPreference = null)
7876
{
7977
$namespace = $databaseName . '.' . $collectionName;
80-
// TODO: inherit from Manager options once PHPC-196 is implemented
81-
$writeConcern = $writeConcern ?: $this->writeConcern;
82-
$readPreference = $readPreference ?: $this->readPreference;
78+
$writeConcern = $writeConcern ?: $this->manager->getWriteConcern();
79+
$readPreference = $readPreference ?: $this->manager->getReadPreference();
8380

8481
return new Collection($this->manager, $namespace, $writeConcern, $readPreference);
8582
}
@@ -97,9 +94,8 @@ public function selectCollection($databaseName, $collectionName, WriteConcern $w
9794
*/
9895
public function selectDatabase($databaseName, WriteConcern $writeConcern = null, ReadPreference $readPreference = null)
9996
{
100-
// TODO: inherit from Manager options once PHPC-196 is implemented
101-
$writeConcern = $writeConcern ?: $this->writeConcern;
102-
$readPreference = $readPreference ?: $this->readPreference;
97+
$writeConcern = $writeConcern ?: $this->manager->getWriteConcern();
98+
$readPreference = $readPreference ?: $this->manager->getReadPreference();
10399

104100
return new Database($this->manager, $databaseName, $writeConcern, $readPreference);
105101
}

src/Operation/Aggregate.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,8 @@ public function execute(Server $server)
122122
return $cursor;
123123
}
124124

125-
$cursor->setTypeMap(array('document' => 'stdClass'));
126125
$result = current($cursor->toArray());
127126

128-
// TODO: Remove this once PHPC-318 is implemented
129-
is_array($result) and $result = (object) $result;
130-
131127
if (empty($result->ok)) {
132128
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
133129
}

src/Operation/Count.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,18 @@ public function __construct($databaseName, $collectionName, array $filter = arra
8585
public function execute(Server $server)
8686
{
8787
$cursor = $server->executeCommand($this->databaseName, $this->createCommand());
88-
$cursor->setTypeMap(array('root' => 'array', 'document' => 'array'));
8988
$result = current($cursor->toArray());
9089

91-
if (empty($result['ok'])) {
92-
throw new RuntimeException(isset($result['errmsg']) ? $result['errmsg'] : 'Unknown error');
90+
if (empty($result->ok)) {
91+
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
9392
}
9493

9594
// Older server versions may return a float
96-
if ( ! isset($result['n']) || ! (is_integer($result['n']) || is_float($result['n']))) {
97-
throw new UnexpectedValueException('count command did not return an "n" value');
95+
if ( ! isset($result->n) || ! (is_integer($result->n) || is_float($result->n))) {
96+
throw new UnexpectedValueException('count command did not return a numeric "n" value');
9897
}
9998

100-
return (integer) $result['n'];
99+
return (integer) $result->n;
101100
}
102101

103102
/**

src/Operation/CreateCollection.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,8 @@ public function __construct($databaseName, $collectionName, array $options = arr
102102
public function execute(Server $server)
103103
{
104104
$cursor = $server->executeCommand($this->databaseName, $this->createCommand());
105-
$cursor->setTypeMap(array('document' => 'stdClass'));
106105
$result = current($cursor->toArray());
107106

108-
// TODO: Remove this once PHPC-318 is implemented
109-
is_array($result) and $result = (object) $result;
110-
111107
if (empty($result->ok)) {
112108
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
113109
}

src/Operation/CreateIndexes.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,10 @@ private function executeCommand(Server $server)
9191
));
9292

9393
$cursor = $server->executeCommand($this->databaseName, $command);
94-
$cursor->setTypeMap(array('root' => 'array', 'document' => 'array'));
9594
$result = current($cursor->toArray());
9695

97-
if (empty($result['ok'])) {
98-
throw new RuntimeException(isset($result['errmsg']) ? $result['errmsg'] : 'Unknown error');
96+
if (empty($result->ok)) {
97+
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
9998
}
10099
}
101100

src/Operation/Distinct.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,8 @@ public function __construct($databaseName, $collectionName, $fieldName, array $f
6262
public function execute(Server $server)
6363
{
6464
$cursor = $server->executeCommand($this->databaseName, $this->createCommand());
65-
$cursor->setTypeMap(array('document' => 'stdClass'));
6665
$result = current($cursor->toArray());
6766

68-
// TODO: Remove this once PHPC-318 is implemented
69-
is_array($result) and $result = (object) $result;
70-
7167
if (empty($result->ok)) {
7268
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
7369
}

src/Operation/DropCollection.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,8 @@ public function __construct($databaseName, $collectionName)
4141
public function execute(Server $server)
4242
{
4343
$cursor = $server->executeCommand($this->databaseName, new Command(array('drop' => $this->collectionName)));
44-
$cursor->setTypeMap(array('document' => 'stdClass'));
4544
$result = current($cursor->toArray());
4645

47-
// TODO: Remove this once PHPC-318 is implemented
48-
is_array($result) and $result = (object) $result;
49-
5046
if (empty($result->ok)) {
5147
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
5248
}

src/Operation/DropDatabase.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,8 @@ public function __construct($databaseName)
3939
public function execute(Server $server)
4040
{
4141
$cursor = $server->executeCommand($this->databaseName, new Command(array('dropDatabase' => 1)));
42-
$cursor->setTypeMap(array('document' => 'stdClass'));
4342
$result = current($cursor->toArray());
4443

45-
// TODO: Remove this once PHPC-318 is implemented
46-
is_array($result) and $result = (object) $result;
47-
4844
if (empty($result->ok)) {
4945
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
5046
}

src/Operation/DropIndexes.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,8 @@ public function execute(Server $server)
5656
);
5757

5858
$cursor = $server->executeCommand($this->databaseName, new Command($cmd));
59-
$cursor->setTypeMap(array('document' => 'stdClass'));
6059
$result = current($cursor->toArray());
6160

62-
// TODO: Remove this once PHPC-318 is implemented
63-
is_array($result) and $result = (object) $result;
64-
6561
if (empty($result->ok)) {
6662
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
6763
}

src/Operation/FindAndModify.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,8 @@ public function __construct($databaseName, $collectionName, array $options)
118118
public function execute(Server $server)
119119
{
120120
$cursor = $server->executeCommand($this->databaseName, $this->createCommand());
121-
$cursor->setTypeMap(array('document' => 'stdClass'));
122121
$result = current($cursor->toArray());
123122

124-
// TODO: Remove this once PHPC-318 is implemented
125-
is_array($result) and $result = (object) $result;
126-
127123
if (empty($result->ok)) {
128124
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
129125
}

0 commit comments

Comments
 (0)