merged mongo into master

This commit is contained in:
Anton Grebnev
2012-06-05 14:08:33 +04:00
5 changed files with 98 additions and 60 deletions

View File

@ -58,14 +58,22 @@ abstract class MongoDbCommand
return $this;
}
protected function arrayToString($array)
{
$string = '[';
if(!empty($array)) {
$string .= PHP_EOL;
}
foreach($array as $key => $value) {
$string .= "\t" . $key . ' = ' . $value . PHP_EOL;
}
$string .= ']' . PHP_EOL;
return $string;
}
abstract protected function concreteExecute();
abstract protected function checkParams();
/**
* @TODO: implement method in subclasses for Profiler
*/
abstract public function __toString();
}
class FindMongoCommand extends MongoDbCommand
@ -98,15 +106,9 @@ class FindMongoCommand extends MongoDbCommand
{
if ($this->checkParams()) {
$result = PHP_EOL . 'Collection: ' . trim($this->collection, "\n") . PHP_EOL;
ob_start();
var_dump($this->condition);
$condition = ob_get_clean();
$result .= 'Condition: ' . $condition;
$result .= 'Condition: ' . $this->arrayToString($this->condition);
$result .= 'Type: FIND' . PHP_EOL;
ob_start();
var_dump($this->fields);
$fields = ob_get_clean();
$result .= 'Fields: ' . $fields . PHP_EOL;
$result .= 'Fields: ' . $this->arrayToString($this->fields);
$mult = $this->multiple ? 'TRUE' : 'FALSE';
$result .= 'Multiple fields: ' . $mult . PHP_EOL;
return $result;
@ -145,10 +147,7 @@ class CountMongoCommand extends MongoDbCommand
if ($this->checkParams()) {
$result = PHP_EOL . 'Collection: ' . trim($this->collection, "\n") . PHP_EOL;
$result .= 'Type: COUNT' . PHP_EOL;
ob_start();
var_dump($this->condition);
$condition = ob_get_clean();
$result .= 'Condition: ' . $condition;
$result .= 'Condition: ' . $this->arrayToString($this->condition);
$result .= 'Limit: ' . $this->limit . PHP_EOL;
$result .= 'Skip: ' . $this->skip . PHP_EOL;
return $result;
@ -201,10 +200,7 @@ class InsertMongoCommand extends MongoDbCommand
if ($this->checkParams()) {
$result = PHP_EOL . 'Collection: ' . trim($this->collection, "\n") . PHP_EOL;
$result .= 'Type: INSERT' . PHP_EOL;
ob_start();
var_dump($this->data);
$data = ob_get_clean();
$result .= 'Data: ' . $data;
$result .= 'Data: ' . $this->arrayToString($this->data);
$mult = $this->multiple ? 'TRUE' : 'FALSE';
$result .= 'Bulk insert: ' . $mult . PHP_EOL;
$safe = $this->safe ? 'TRUE' : 'FALSE';
@ -250,14 +246,8 @@ class UpdateMongoCommand extends MongoDbCommand
if ($this->checkParams()) {
$result = PHP_EOL . 'Collection: ' . trim($this->collection, "\n") . PHP_EOL;
$result .= 'Type: UPDATE' . PHP_EOL;
ob_start();
var_dump($this->condition);
$condition = ob_get_clean();
$result .= 'Condition: ' . $condition;
ob_start();
var_dump($this->data);
$data = ob_get_clean();
$result .= 'Data: ' . $data;
$result .= 'Condition: ' . $this->arrayToString($this->condition);
$result .= 'Data: ' . $this->arrayToString($this->data);
$mult = $this->multiple ? 'TRUE' : 'FALSE';
$result .= 'Multiple fields: ' . $mult . PHP_EOL;
$upsert = $this->upsert ? 'TRUE' : 'FALSE';
@ -296,10 +286,7 @@ class RemoveMongoCommand extends MongoDbCommand
if ($this->checkParams()) {
$result = PHP_EOL . 'Collection: ' . trim($this->collection, "\n") . PHP_EOL;
$result .= 'Type: REMOVE' . PHP_EOL;
ob_start();
var_dump($this->condition);
$condition = ob_get_clean();
$result .= 'Condition: ' . $condition;
$result .= 'Condition: ' . $this->arrayToString($this->condition);
$safe = $this->safe ? 'TRUE' : 'FALSE';
$result .= 'Safe operation: ' . $safe . PHP_EOL;
return $result;
@ -337,10 +324,7 @@ class CommandMongoCommand extends MongoDbCommand
if ($this->checkParams()) {
$result = PHP_EOL . 'Collection: ' . trim($this->collection, "\n") . PHP_EOL;
$result .= 'Type: COMMAND' . PHP_EOL;
ob_start();
var_dump($this->command);
$command = ob_get_clean();
$result .= 'Command: ' . $command;
$result .= 'Command: ' . $this->arrayToString($this->command);
return $result;
} else {
return 'Command properties not set';

View File

@ -60,8 +60,10 @@ class MongoStatement extends DbStatement
if (!$this->result) {
return false;
}
if (is_array($this->result) && isset($this->result['retval'])) {
return $this->result['retval'];
}
$row = false;
switch ($style) {
case Db::FETCH_OBJ:
$row = $this->fetchObject();
@ -133,6 +135,7 @@ class MongoStatement extends DbStatement
*/
protected function driverExecute($request)
{
$this->result = false;
$mongo = $this->driver->getConnection();
if ($mongo instanceof Mongo) {
if (DEBUG) {
@ -179,4 +182,4 @@ class MongoStatement extends DbStatement
{
return $this->insertId;
}
}
}