Commit e223a19c authored by Jeremy Mikola's avatar Jeremy Mikola

Rely on default type map conversion

parent 4b84bd96
......@@ -122,12 +122,8 @@ class Aggregate implements Executable
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');
}
......
......@@ -85,19 +85,18 @@ class Count implements Executable
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;
}
/**
......
......@@ -102,12 +102,8 @@ class CreateCollection implements Executable
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');
}
......
......@@ -91,11 +91,10 @@ class CreateIndexes implements Executable
));
$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');
}
}
......
......@@ -62,12 +62,8 @@ class Distinct implements Executable
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');
}
......
......@@ -41,12 +41,8 @@ class DropCollection implements Executable
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');
}
......
......@@ -39,12 +39,8 @@ class DropDatabase implements Executable
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');
}
......
......@@ -56,12 +56,8 @@ class DropIndexes implements Executable
);
$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');
}
......
......@@ -118,12 +118,8 @@ class FindAndModify implements Executable
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');
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment