removed output buffer(ob_start/ob_end_clean) usasge in MongoDbCommand profile output
This commit is contained in:
@ -58,14 +58,22 @@ abstract class MongoDbCommand
|
|||||||
return $this;
|
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 concreteExecute();
|
||||||
|
|
||||||
abstract protected function checkParams();
|
abstract protected function checkParams();
|
||||||
|
|
||||||
/**
|
|
||||||
* @TODO: implement method in subclasses for Profiler
|
|
||||||
*/
|
|
||||||
abstract public function __toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class FindMongoCommand extends MongoDbCommand
|
class FindMongoCommand extends MongoDbCommand
|
||||||
@ -98,15 +106,9 @@ class FindMongoCommand extends MongoDbCommand
|
|||||||
{
|
{
|
||||||
if ($this->checkParams()) {
|
if ($this->checkParams()) {
|
||||||
$result = PHP_EOL . 'Collection: ' . $this->collection . PHP_EOL;
|
$result = PHP_EOL . 'Collection: ' . $this->collection . PHP_EOL;
|
||||||
ob_start();
|
$result .= 'Condition: ' . $this->arrayToString($this->condition);
|
||||||
var_dump($this->condition);
|
|
||||||
$condition = ob_get_clean();
|
|
||||||
$result .= 'Condition: ' . $condition;
|
|
||||||
$result .= 'Type: FIND' . PHP_EOL;
|
$result .= 'Type: FIND' . PHP_EOL;
|
||||||
ob_start();
|
$result .= 'Fields: ' . $this->arrayToString($this->fields);
|
||||||
var_dump($this->fields);
|
|
||||||
$fields = ob_get_clean();
|
|
||||||
$result .= 'Fields: ' . $fields . PHP_EOL;
|
|
||||||
$mult = $this->multiple ? 'TRUE' : 'FALSE';
|
$mult = $this->multiple ? 'TRUE' : 'FALSE';
|
||||||
$result .= 'Multiple fields: ' . $mult . PHP_EOL;
|
$result .= 'Multiple fields: ' . $mult . PHP_EOL;
|
||||||
return $result;
|
return $result;
|
||||||
@ -145,10 +147,7 @@ class CountMongoCommand extends MongoDbCommand
|
|||||||
if ($this->checkParams()) {
|
if ($this->checkParams()) {
|
||||||
$result = PHP_EOL . 'Collection: ' . $this->collection . PHP_EOL;
|
$result = PHP_EOL . 'Collection: ' . $this->collection . PHP_EOL;
|
||||||
$result .= 'Type: COUNT' . PHP_EOL;
|
$result .= 'Type: COUNT' . PHP_EOL;
|
||||||
ob_start();
|
$result .= 'Condition: ' . $this->arrayToString($this->condition);
|
||||||
var_dump($this->condition);
|
|
||||||
$condition = ob_get_clean();
|
|
||||||
$result .= 'Condition: ' . $condition;
|
|
||||||
$result .= 'Limit: ' . $this->limit . PHP_EOL;
|
$result .= 'Limit: ' . $this->limit . PHP_EOL;
|
||||||
$result .= 'Skip: ' . $this->skip . PHP_EOL;
|
$result .= 'Skip: ' . $this->skip . PHP_EOL;
|
||||||
return $result;
|
return $result;
|
||||||
@ -201,10 +200,7 @@ class InsertMongoCommand extends MongoDbCommand
|
|||||||
if ($this->checkParams()) {
|
if ($this->checkParams()) {
|
||||||
$result = PHP_EOL . 'Collection: ' . $this->collection . PHP_EOL;
|
$result = PHP_EOL . 'Collection: ' . $this->collection . PHP_EOL;
|
||||||
$result .= 'Type: INSERT' . PHP_EOL;
|
$result .= 'Type: INSERT' . PHP_EOL;
|
||||||
ob_start();
|
$result .= 'Data: ' . $this->arrayToString($this->data);
|
||||||
var_dump($this->data);
|
|
||||||
$data = ob_get_clean();
|
|
||||||
$result .= 'Data: ' . $data;
|
|
||||||
$mult = $this->multiple ? 'TRUE' : 'FALSE';
|
$mult = $this->multiple ? 'TRUE' : 'FALSE';
|
||||||
$result .= 'Bulk insert: ' . $mult . PHP_EOL;
|
$result .= 'Bulk insert: ' . $mult . PHP_EOL;
|
||||||
$safe = $this->safe ? 'TRUE' : 'FALSE';
|
$safe = $this->safe ? 'TRUE' : 'FALSE';
|
||||||
@ -250,14 +246,8 @@ class UpdateMongoCommand extends MongoDbCommand
|
|||||||
if ($this->checkParams()) {
|
if ($this->checkParams()) {
|
||||||
$result = PHP_EOL . 'Collection: ' . $this->collection . PHP_EOL;
|
$result = PHP_EOL . 'Collection: ' . $this->collection . PHP_EOL;
|
||||||
$result .= 'Type: UPDATE' . PHP_EOL;
|
$result .= 'Type: UPDATE' . PHP_EOL;
|
||||||
ob_start();
|
$result .= 'Condition: ' . $this->arrayToString($this->condition);
|
||||||
var_dump($this->condition);
|
$result .= 'Data: ' . $this->arrayToString($this->data);
|
||||||
$condition = ob_get_clean();
|
|
||||||
$result .= 'Condition: ' . $condition;
|
|
||||||
ob_start();
|
|
||||||
var_dump($this->data);
|
|
||||||
$data = ob_get_clean();
|
|
||||||
$result .= 'Data: ' . $data;
|
|
||||||
$mult = $this->multiple ? 'TRUE' : 'FALSE';
|
$mult = $this->multiple ? 'TRUE' : 'FALSE';
|
||||||
$result .= 'Multiple fields: ' . $mult . PHP_EOL;
|
$result .= 'Multiple fields: ' . $mult . PHP_EOL;
|
||||||
$upsert = $this->upsert ? 'TRUE' : 'FALSE';
|
$upsert = $this->upsert ? 'TRUE' : 'FALSE';
|
||||||
@ -296,10 +286,7 @@ class RemoveMongoCommand extends MongoDbCommand
|
|||||||
if ($this->checkParams()) {
|
if ($this->checkParams()) {
|
||||||
$result = PHP_EOL . 'Collection: ' . $this->collection . PHP_EOL;
|
$result = PHP_EOL . 'Collection: ' . $this->collection . PHP_EOL;
|
||||||
$result .= 'Type: REMOVE' . PHP_EOL;
|
$result .= 'Type: REMOVE' . PHP_EOL;
|
||||||
ob_start();
|
$result .= 'Condition: ' . $this->arrayToString($this->condition);
|
||||||
var_dump($this->condition);
|
|
||||||
$condition = ob_get_clean();
|
|
||||||
$result .= 'Condition: ' . $condition;
|
|
||||||
$safe = $this->safe ? 'TRUE' : 'FALSE';
|
$safe = $this->safe ? 'TRUE' : 'FALSE';
|
||||||
$result .= 'Safe operation: ' . $safe . PHP_EOL;
|
$result .= 'Safe operation: ' . $safe . PHP_EOL;
|
||||||
return $result;
|
return $result;
|
||||||
@ -337,10 +324,7 @@ class CommandMongoCommand extends MongoDbCommand
|
|||||||
if ($this->checkParams()) {
|
if ($this->checkParams()) {
|
||||||
$result = PHP_EOL . 'Collection: ' . $this->collection . PHP_EOL;
|
$result = PHP_EOL . 'Collection: ' . $this->collection . PHP_EOL;
|
||||||
$result .= 'Type: COMMAND' . PHP_EOL;
|
$result .= 'Type: COMMAND' . PHP_EOL;
|
||||||
ob_start();
|
$result .= 'Command: ' . $this->arrayToString($this->command);
|
||||||
var_dump($this->command);
|
|
||||||
$command = ob_get_clean();
|
|
||||||
$result .= 'Command: ' . $command;
|
|
||||||
return $result;
|
return $result;
|
||||||
} else {
|
} else {
|
||||||
return 'Command properties not set';
|
return 'Command properties not set';
|
||||||
|
@ -334,6 +334,7 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase
|
|||||||
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, new CollectionMock());
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, new CollectionMock());
|
||||||
$cmd->bindParam('condition', array());
|
$cmd->bindParam('condition', array());
|
||||||
$this->assertStringStartsWith("\n" . 'Collection: CollectionMock', $cmd->__toString());
|
$this->assertStringStartsWith("\n" . 'Collection: CollectionMock', $cmd->__toString());
|
||||||
|
$this->assertContains('Condition: ' . '[]' . PHP_EOL, $cmd->__toString());
|
||||||
|
|
||||||
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::COMMAND, new CollectionMock());
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::COMMAND, new CollectionMock());
|
||||||
$this->assertSame('Command properties not set', $cmd->__toString());
|
$this->assertSame('Command properties not set', $cmd->__toString());
|
||||||
@ -347,6 +348,7 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase
|
|||||||
->bindParam('safe', true);
|
->bindParam('safe', true);
|
||||||
$this->assertStringStartsWith("\n" . 'Collection: ', $cmd->__toString());
|
$this->assertStringStartsWith("\n" . 'Collection: ', $cmd->__toString());
|
||||||
$this->assertContains('Bulk insert: FALSE', $cmd->__toString());
|
$this->assertContains('Bulk insert: FALSE', $cmd->__toString());
|
||||||
|
$this->assertContains('Data: ' . '[' . PHP_EOL . "\tname = insert" . PHP_EOL . ']' . PHP_EOL, $cmd->__toString());
|
||||||
|
|
||||||
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $this->collection);
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $this->collection);
|
||||||
$this->assertSame('Command properties not set', $cmd->__toString());
|
$this->assertSame('Command properties not set', $cmd->__toString());
|
||||||
|
Reference in New Issue
Block a user