4 * This file is part of Twig.
6 * (c) 2010 Fabien Potencier
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
13 * Twig_Node_SandboxedPrint adds a check for the __toString() method
14 * when the variable is an object and the sandbox is activated.
16 * When there is a simple Print statement, like {{ article }},
17 * and if the sandbox is enabled, we need to check that the __toString()
18 * method is allowed if 'article' is an object.
20 * @author Fabien Potencier <fabien@symfony.com>
22 class Twig_Node_SandboxedPrint
extends Twig_Node_Print
24 public function __construct(Twig_Node_Expression
$expr, $lineno, $tag = null)
26 parent
::__construct($expr, $lineno, $tag);
30 * Compiles the node to PHP.
32 * @param Twig_Compiler A Twig_Compiler instance
34 public function compile(Twig_Compiler
$compiler)
38 ->write('echo $this->env->getExtension(\'sandbox\')->ensureToStringAllowed(')
39 ->subcompile($this->getNode('expr'))
45 * Removes node filters.
47 * This is mostly needed when another visitor adds filters (like the escaper one).
49 * @param Twig_Node $node A Node
51 protected function removeNodeFilter($node)
53 if ($node instanceof Twig_Node_Expression_Filter
) {
54 return $this->removeNodeFilter($node->getNode('node'));