*/
class Twig_Node_SandboxedPrint extends Twig_Node_Print
{
- public function __construct(Twig_Node_Print $node)
+ public function __construct(Twig_Node_Expression $expr, $lineno, $tag = null)
{
- parent::__construct($node->getNode('expr'), $node->getLine(), $node->getNodeTag());
+ parent::__construct($expr, $lineno, $tag);
}
/**
->raw('$_tmp, \'__toString\');'."\n")
->outdent()
->write('}'."\n")
- ->write('echo ')
- ->raw("\$_tmp;\n")
;
+
+ parent::compile($compiler);
}
}
return $node;
}
- return new Twig_Node_Print(
+ $class = get_class($node);
+
+ return new $class(
$this->getEscaperFilter($type, $expression),
$node->getLine()
);
// wrap print to check __toString() calls
if ($node instanceof Twig_Node_Print) {
- return new Twig_Node_SandboxedPrint($node);
+ return new Twig_Node_SandboxedPrint($node->getNode('expr'), $node->getLine(), $node->getNodeTag());
}
}
*/
public function testConstructor()
{
- $expr = new Twig_Node_Expression_Constant('foo', 0);
- $node = new Twig_Node_Print($expr, 0);
- $node = new Twig_Node_SandboxedPrint($node);
+ $node = new Twig_Node_SandboxedPrint($expr = new Twig_Node_Expression_Constant('foo', 0), 0);
$this->assertEquals($expr, $node->getNode('expr'));
}
{
$tests = array();
- $node = new Twig_Node_Print(new Twig_Node_Expression_Constant('foo', 0), 0);
- $tests[] = array(new Twig_Node_SandboxedPrint($node), <<<EOF
-\$_tmp = "foo";
-if (is_object(\$_tmp)) {
+ $tests[] = array(new Twig_Node_SandboxedPrint(new Twig_Node_Expression_Constant('foo', 0), 0), <<<EOF
+if (is_object(\$_tmp = "foo")) {
\$this->env->getExtension('sandbox')->checkMethodAllowed(\$_tmp, '__toString');
}
-echo \$_tmp;
+echo "foo";
EOF
);