Example #1
0
 protected function escapePrintNode(Twig_Node_Print $node, Twig_Environment $env, $type)
 {
     if (false === $type) {
         return $node;
     }
     $expression = $node->getNode('expr');
     if ($this->isSafeFor($type, $expression, $env)) {
         return $node;
     }
     $class = get_class($node);
     return new $class($this->getEscaperFilter($type, $expression), $node->getLine());
 }
 public function __construct(Twig_Node_Expression $expr, $lineno, $tag = null)
 {
     parent::__construct($expr, $lineno, $tag);
 }
Example #3
0
 public function compile($compiler)
 {
     $compiler->addDebugInfo($this)->write('if ($this->env->hasExtension(\'sandbox\') && is_object(')->subcompile($this->expr)->raw(')) {' . "\n")->indent()->write('$this->env->getExtension(\'sandbox\')->checkMethodAllowed(')->subcompile($this->expr)->raw(', \'__toString\');' . "\n")->outdent()->write('}' . "\n");
     parent::compile($compiler);
 }
 /**
  * Compiles the node to PHP.
  *
  * @param Twig_Compiler A Twig_Compiler instance
  */
 public function compile(Twig_Compiler $compiler)
 {
     $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");
     parent::compile($compiler);
 }
 /**
  * @covers Twig_Node_Print::__construct
  */
 public function testConstructor()
 {
     $expr = new Twig_Node_Expression_Constant('foo', 0);
     $node = new Twig_Node_Print($expr, 0);
     $this->assertEquals($expr, $node->getNode('expr'));
 }