|
|
@ -12,6 +12,8 @@ class MongoCommandBuilder |
|
|
|
|
|
|
|
const FIND = 'Find'; |
|
|
|
|
|
|
|
const COUNT = 'Count'; |
|
|
|
|
|
|
|
const INSERT = 'Insert'; |
|
|
|
|
|
|
|
const UPDATE = 'Update'; |
|
|
@ -68,9 +70,9 @@ abstract class MongoDbCommand |
|
|
|
|
|
|
|
class FindMongoCommand extends MongoDbCommand |
|
|
|
{ |
|
|
|
protected $condition; |
|
|
|
protected $condition = array(); |
|
|
|
|
|
|
|
protected $fields; |
|
|
|
protected $fields = array(); |
|
|
|
|
|
|
|
protected $multiple = true; |
|
|
|
|
|
|
@ -100,6 +102,7 @@ class FindMongoCommand extends MongoDbCommand |
|
|
|
var_dump($this->condition); |
|
|
|
$condition = ob_get_clean(); |
|
|
|
$result .= 'Condition: ' . $condition . PHP_EOL; |
|
|
|
$result .= 'Type: FIND' . PHP_EOL; |
|
|
|
ob_start(); |
|
|
|
var_dump($this->fields); |
|
|
|
$fields = ob_get_clean(); |
|
|
@ -113,6 +116,48 @@ class FindMongoCommand extends MongoDbCommand |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
class CountMongoCommand extends MongoDbCommand |
|
|
|
{ |
|
|
|
protected $condition = array(); |
|
|
|
|
|
|
|
protected $limit = 0; |
|
|
|
|
|
|
|
protected $skip = 0; |
|
|
|
|
|
|
|
protected $multiple = true; |
|
|
|
|
|
|
|
protected function concreteExecute() |
|
|
|
{ |
|
|
|
return $this->collection->count($this->condition, $this->limit, $this->skip); |
|
|
|
} |
|
|
|
|
|
|
|
protected function checkParams() |
|
|
|
{ |
|
|
|
if (isset($this->collection) && isset($this->condition) && isset($this->limit) && isset($this->skip)) { |
|
|
|
return true; |
|
|
|
} else { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function __toString() |
|
|
|
{ |
|
|
|
if ($this->checkParams()) { |
|
|
|
$result = 'Collection: ' . $this->collection . PHP_EOL; |
|
|
|
$result .= 'Type: COUNT' . PHP_EOL; |
|
|
|
ob_start(); |
|
|
|
var_dump($this->condition); |
|
|
|
$condition = ob_get_clean(); |
|
|
|
$result .= 'Condition: ' . $condition . PHP_EOL; |
|
|
|
$result .= 'Limit: ' . $this->limit . PHP_EOL; |
|
|
|
$result .= 'Skip: ' . $this->skip . PHP_EOL; |
|
|
|
return $result; |
|
|
|
} else { |
|
|
|
return 'Command properties not set'; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
class InsertMongoCommand extends MongoDbCommand |
|
|
|
{ |
|
|
|
protected $data; |
|
|
@ -155,6 +200,7 @@ class InsertMongoCommand extends MongoDbCommand |
|
|
|
{ |
|
|
|
if ($this->checkParams()) { |
|
|
|
$result = 'Collection: ' . $this->collection . PHP_EOL; |
|
|
|
$result .= 'Type: INSERT' . PHP_EOL; |
|
|
|
ob_start(); |
|
|
|
var_dump($this->data); |
|
|
|
$data = ob_get_clean(); |
|
|
@ -203,6 +249,7 @@ class UpdateMongoCommand extends MongoDbCommand |
|
|
|
{ |
|
|
|
if ($this->checkParams()) { |
|
|
|
$result = 'Collection: ' . $this->collection . PHP_EOL; |
|
|
|
$result .= 'Type: UPDATE' . PHP_EOL; |
|
|
|
ob_start(); |
|
|
|
var_dump($this->condition); |
|
|
|
$condition = ob_get_clean(); |
|
|
@ -248,6 +295,7 @@ class RemoveMongoCommand extends MongoDbCommand |
|
|
|
{ |
|
|
|
if ($this->checkParams()) { |
|
|
|
$result = 'Collection: ' . $this->collection . PHP_EOL; |
|
|
|
$result .= 'Type: REMOVE' . PHP_EOL; |
|
|
|
ob_start(); |
|
|
|
var_dump($this->condition); |
|
|
|
$condition = ob_get_clean(); |
|
|
@ -288,6 +336,7 @@ class CommandMongoCommand extends MongoDbCommand |
|
|
|
{ |
|
|
|
if ($this->checkParams()) { |
|
|
|
$result = 'Collection: ' . $this->collection . PHP_EOL; |
|
|
|
$result .= 'Type: COMMAND' . PHP_EOL; |
|
|
|
ob_start(); |
|
|
|
var_dump($this->command); |
|
|
|
$command = ob_get_clean(); |
|
|
|