[ExpressionLanguage] Move the ::dump method to the Node classe to ease its usage
This commit is contained in:
parent
865f344143
commit
b6d0050c38
@ -81,6 +81,17 @@ class Node
|
|||||||
throw new \BadMethodCallException(sprintf('Dumping a "%s" instance is not supported yet.', get_class($this)));
|
throw new \BadMethodCallException(sprintf('Dumping a "%s" instance is not supported yet.', get_class($this)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function dump()
|
||||||
|
{
|
||||||
|
$dump = '';
|
||||||
|
|
||||||
|
foreach ($this->toArray() as $v) {
|
||||||
|
$dump .= is_scalar($v) ? $v : $v->dump();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $dump;
|
||||||
|
}
|
||||||
|
|
||||||
protected function dumpString($value)
|
protected function dumpString($value)
|
||||||
{
|
{
|
||||||
return sprintf('"%s"', addcslashes($value, "\0\t\"\\"));
|
return sprintf('"%s"', addcslashes($value, "\0\t\"\\"));
|
||||||
|
@ -39,20 +39,4 @@ class ParsedExpression extends Expression
|
|||||||
{
|
{
|
||||||
return $this->nodes;
|
return $this->nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dump()
|
|
||||||
{
|
|
||||||
return $this->dumpNode($this->nodes);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function dumpNode(Node $node)
|
|
||||||
{
|
|
||||||
$dump = '';
|
|
||||||
|
|
||||||
foreach ($node->toArray() as $v) {
|
|
||||||
$dump .= is_scalar($v) ? $v : $this->dumpNode($v);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $dump;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
namespace Symfony\Component\ExpressionLanguage\Tests\Node;
|
namespace Symfony\Component\ExpressionLanguage\Tests\Node;
|
||||||
|
|
||||||
use Symfony\Component\ExpressionLanguage\Compiler;
|
use Symfony\Component\ExpressionLanguage\Compiler;
|
||||||
use Symfony\Component\ExpressionLanguage\ParsedExpression;
|
|
||||||
|
|
||||||
abstract class AbstractNodeTest extends \PHPUnit_Framework_TestCase
|
abstract class AbstractNodeTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
@ -43,8 +42,7 @@ abstract class AbstractNodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testDump($expected, $node)
|
public function testDump($expected, $node)
|
||||||
{
|
{
|
||||||
$expr = new ParsedExpression($expected, $node);
|
$this->assertSame($expected, $node->dump());
|
||||||
$this->assertSame($expected, $expr->dump());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract public function getDumpData();
|
abstract public function getDumpData();
|
||||||
|
Reference in New Issue
Block a user