1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
<?php
/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Checks if casting an expression to __toString() is allowed by the sandbox.
*
* For instance, when there is a simple Print statement, like {{ article }},
* and if the sandbox is enabled, we need to check that the __toString()
* method is allowed if 'article' is an object. The same goes for {{ article|upper }}
* or {{ random(article) }}
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class Twig_Node_CheckToString extends Twig_Node
{
public function __construct(Twig_Node_Expression $expr)
{
parent::__construct(['expr' => $expr], [], $expr->getTemplateLine(), $expr->getNodeTag());
}
public function compile(Twig_Compiler $compiler)
{
$compiler
->write('$this->extensions[\'Twig_Extension_Sandbox\']->ensureToStringAllowed(')
->subcompile($this->getNode('expr'))
->raw(')')
;
}
}
class_alias('Twig_Node_CheckToString', 'Twig\Node\CheckToStringNode', false);
|