Commit f1481d95 authored by guilhermeblanco's avatar guilhermeblanco

[2.0] Added dump function for AST nodes to help debugging complex queries

parent 87979219
......@@ -35,4 +35,54 @@ namespace Doctrine\ORM\Query\AST;
abstract class Node
{
abstract public function dispatch($sqlWalker);
/**
* Dumps the AST Node into a string representation for information purpose only
*
* @return string
*/
public function __toString()
{
return $this->dump($this);
}
public function dump($obj)
{
static $ident = 0;
$str = '';
if ($obj instanceof Node) {
$str .= get_class($obj) . '(' . PHP_EOL;
$props = get_object_vars($obj);
foreach ($props as $name => $prop) {
$ident += 4;
$str .= str_repeat(' ', $ident) . '"' . $name . '": '
. $this->dump($prop) . ',' . PHP_EOL;
$ident -= 4;
}
$str .= str_repeat(' ', $ident) . ')';
} else if (is_array($obj)) {
$ident += 4;
$str .= 'array(';
$some = false;
foreach ($obj as $k => $v) {
$str .= PHP_EOL . str_repeat(' ', $ident) . '"'
. $k . '" => ' . $this->dump($v) . ',';
$some = true;
}
$ident -= 4;
$str .= ($some ? PHP_EOL . str_repeat(' ', $ident) : '') . ')';
} else if (is_object($obj)) {
$str .= 'instanceof(' . get_class($obj) . ')';
} else {
$str .= var_export($obj, true);
}
return $str;
}
}
\ No newline at end of file
......@@ -257,6 +257,8 @@ class Parser
{
// Parse & build AST
$AST = $this->QueryLanguage();
echo PHP_EOL . ((string) $AST) . PHP_EOL;
// Check for end of string
if ($this->_lexer->lookahead !== null) {
......
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