added __toString() for MongoDbCommands
This commit is contained in:
@ -63,10 +63,7 @@ abstract class MongoDbCommand
|
||||
/**
|
||||
* @TODO: implement method in subclasses for Profiler
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return get_called_class();
|
||||
}
|
||||
abstract public function __toString();
|
||||
}
|
||||
|
||||
class FindMongoCommand extends MongoDbCommand
|
||||
@ -79,7 +76,7 @@ class FindMongoCommand extends MongoDbCommand
|
||||
|
||||
protected function concreteExecute()
|
||||
{
|
||||
if($this->multiple) {
|
||||
if ($this->multiple) {
|
||||
return $this->collection->find($this->condition, $this->fields);
|
||||
} else {
|
||||
return $this->collection->findOne($this->condition, $this->fields);
|
||||
@ -94,6 +91,26 @@ class FindMongoCommand extends MongoDbCommand
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
if ($this->checkParams()) {
|
||||
$result = 'Collection: ' . $this->collection . PHP_EOL;
|
||||
ob_start();
|
||||
var_dump($this->condition);
|
||||
$condition = ob_get_clean();
|
||||
$result .= 'Condition: ' . $condition . PHP_EOL;
|
||||
ob_start();
|
||||
var_dump($this->fields);
|
||||
$fields = ob_get_clean();
|
||||
$result .= 'Fields: ' . $fields . PHP_EOL;
|
||||
$mult = $this->multiple ? 'TRUE' : 'FALSE';
|
||||
$result .= 'Multiple fields: ' . $mult . PHP_EOL;
|
||||
return $result;
|
||||
} else {
|
||||
return 'Command properties not set';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class InsertMongoCommand extends MongoDbCommand
|
||||
@ -124,6 +141,22 @@ class InsertMongoCommand extends MongoDbCommand
|
||||
{
|
||||
return $this->insertId;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
if ($this->checkParams()) {
|
||||
$result = 'Collection: ' . $this->collection . PHP_EOL;
|
||||
ob_start();
|
||||
var_dump($this->data);
|
||||
$data = ob_get_clean();
|
||||
$result .= 'Data: ' . $data . PHP_EOL;
|
||||
$safe = $this->safe ? 'TRUE' : 'FALSE';
|
||||
$result .= 'Safe operation: ' . $safe . PHP_EOL;
|
||||
return $result;
|
||||
} else {
|
||||
return 'Command properties not set';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class UpdateMongoCommand extends MongoDbCommand
|
||||
@ -154,6 +187,30 @@ class UpdateMongoCommand extends MongoDbCommand
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
if ($this->checkParams()) {
|
||||
$result = 'Collection: ' . $this->collection . PHP_EOL;
|
||||
ob_start();
|
||||
var_dump($this->condition);
|
||||
$condition = ob_get_clean();
|
||||
$result .= 'Condition: ' . $condition . PHP_EOL;
|
||||
ob_start();
|
||||
var_dump($this->data);
|
||||
$data = ob_get_clean();
|
||||
$result .= 'Data: ' . $data . PHP_EOL;
|
||||
$mult = $this->multiple ? 'TRUE' : 'FALSE';
|
||||
$result .= 'Multiple fields: ' . $mult . PHP_EOL;
|
||||
$upsert = $this->upsert ? 'TRUE' : 'FALSE';
|
||||
$result .= 'Upsert: ' . $upsert . PHP_EOL;
|
||||
$safe = $this->safe ? 'TRUE' : 'FALSE';
|
||||
$result .= 'Safe operation: ' . $safe . PHP_EOL;
|
||||
return $result;
|
||||
} else {
|
||||
return 'Command properties not set';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class RemoveMongoCommand extends MongoDbCommand
|
||||
@ -175,21 +232,37 @@ class RemoveMongoCommand extends MongoDbCommand
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
if ($this->checkParams()) {
|
||||
$result = 'Collection: ' . $this->collection . PHP_EOL;
|
||||
ob_start();
|
||||
var_dump($this->condition);
|
||||
$condition = ob_get_clean();
|
||||
$result .= 'Condition: ' . $condition . PHP_EOL;
|
||||
$safe = $this->safe ? 'TRUE' : 'FALSE';
|
||||
$result .= 'Safe operation: ' . $safe . PHP_EOL;
|
||||
return $result;
|
||||
} else {
|
||||
return 'Command properties not set';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class CommandMongoCommand extends MongoDbCommand
|
||||
{
|
||||
protected $command;
|
||||
class CommandMongoCommand extends MongoDbCommand
|
||||
{
|
||||
protected $command;
|
||||
|
||||
protected function concreteExecute()
|
||||
{
|
||||
$db = $this->collection->db;
|
||||
if($db instanceof MongoDB) {
|
||||
return $db->command($this->command);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
protected function concreteExecute()
|
||||
{
|
||||
$db = $this->collection->db;
|
||||
if ($db instanceof MongoDB) {
|
||||
return $db->command($this->command);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected function checkParams()
|
||||
{
|
||||
@ -199,4 +272,18 @@ class RemoveMongoCommand extends MongoDbCommand
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
if ($this->checkParams()) {
|
||||
$result = 'Collection: ' . $this->collection . PHP_EOL;
|
||||
ob_start();
|
||||
var_dump($this->command);
|
||||
$command = ob_get_clean();
|
||||
$result .= 'Command: ' . $command . PHP_EOL;
|
||||
return $result;
|
||||
} else {
|
||||
return 'Command properties not set';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user