/**
  * @param \Twig_Compiler $compiler
  */
 public function compile(\Twig_Compiler $compiler)
 {
     $compiler->addDebugInfo($this);
     $body = $this->getNode('body');
     if ($body instanceof \Twig_Node_Expression_Constant) {
         $body = new \Twig_Node_Expression_Constant(trim($body->getAttribute('value')), $body->getLine());
     } elseif ($body instanceof \Twig_Node_Text) {
         $body = new \Twig_Node_Expression_Constant(trim($body->getAttribute('data')), $body->getLine());
     }
     $compiler->write('echo $this->env->getExtension(\'ivoaz_content_editable\')->render(')->subcompile($body)->raw(',')->repr($this->getAttribute('name'))->raw(',')->repr($this->getAttribute('options'))->raw(');');
 }
示例#2
0
 public function __construct(Twig_NodeInterface $node, Twig_Node_Expression_Constant $filterName, Twig_NodeInterface $arguments, $lineno, $tag = null)
 {
     $default = new Twig_Node_Expression_Filter($node, new Twig_Node_Expression_Constant('_default', $node->getLine()), $arguments, $node->getLine());
     if ('default' === $filterName->getAttribute('value') && ($node instanceof Twig_Node_Expression_Name || $node instanceof Twig_Node_Expression_GetAttr)) {
         $test = new Twig_Node_Expression_Test_Defined(clone $node, 'defined', new Twig_Node(), $node->getLine());
         $false = count($arguments) ? $arguments->getNode(0) : new Twig_Node_Expression_Constant('', $node->getLine());
         $node = new Twig_Node_Expression_Conditional($test, $default, $false, $node->getLine());
     } else {
         $node = $default;
     }
     parent::__construct($node, $filterName, $arguments, $lineno, $tag);
 }
示例#3
0
文件: Defined.php 项目: mat33470/PFA
 public function __construct(Twig_NodeInterface $node, $name, Twig_NodeInterface $arguments = null, $lineno)
 {
     if ($node instanceof Twig_Node_Expression_Name) {
         $node->setAttribute('is_defined_test', true);
     } elseif ($node instanceof Twig_Node_Expression_GetAttr) {
         $node->setAttribute('is_defined_test', true);
         $this->changeIgnoreStrictCheck($node);
     } elseif ($node instanceof Twig_Node_Expression_Constant || $node instanceof Twig_Node_Expression_Array) {
         $node = new Twig_Node_Expression_Constant(true, $node->getLine());
     } else {
         throw new Twig_Error_Syntax('The "defined" test only works with simple variables.', $this->getLine());
     }
     parent::__construct($node, $name, $arguments, $lineno);
 }
示例#4
0
 public function parseFilterExpressionRaw($node, $tag = null)
 {
     while (true) {
         $token = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE);
         $name = new Twig_Node_Expression_Constant($token->getValue(), $token->getLine());
         if (!$this->parser->getStream()->test(Twig_Token::PUNCTUATION_TYPE, '(')) {
             $arguments = new Twig_Node();
         } else {
             $arguments = $this->parseArguments(true);
         }
         $class = $this->getFilterNodeClass($name->getAttribute('value'), $token->getLine());
         $node = new $class($node, $name, $arguments, $token->getLine(), $tag);
         if (!$this->parser->getStream()->test(Twig_Token::PUNCTUATION_TYPE, '|')) {
             break;
         }
         $this->parser->getStream()->next();
     }
     return $node;
 }
示例#5
0
 public function testConstructor()
 {
     $node = new Twig_Node_Expression_Constant('foo', 1);
     $this->assertEquals('foo', $node->getAttribute('value'));
 }