1
0
mirror of synced 2024-12-12 22:36:02 +03:00

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

This commit is contained in:
guilhermeblanco 2009-08-11 22:11:33 +00:00
parent 8797921937
commit f1481d9506
2 changed files with 52 additions and 0 deletions

View File

@ -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;
}
}

View 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) {