}
}
+ public function ensureToStringAllowed($obj)
+ {
+ if (is_object($obj)) {
+ $this->policy->checkMethodAllowed($obj, '__toString');
+ }
+
+ return $obj;
+ }
+
/**
* Returns the name of the extension.
*
{
$compiler
->addDebugInfo($this)
- ->write('if (is_object(')
- ->raw('$_tmp = ')
- ->subcompile($this->removeNodeFilter($this->getNode('expr')))
- ->raw(')) {'."\n")
- ->indent()
- ->write('$this->env->getExtension(\'sandbox\')->checkMethodAllowed(')
- ->raw('$_tmp, \'__toString\');'."\n")
- ->outdent()
- ->write('}'."\n")
+ ->write('echo $this->env->getExtension(\'sandbox\')->ensureToStringAllowed(')
+ ->subcompile($this->getNode('expr'))
+ ->raw(");\n")
;
-
- parent::compile($compiler);
}
/**
$tests = array();
$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 "foo";
+echo \$this->env->getExtension('sandbox')->ensureToStringAllowed("foo");
EOF
);