当前位置: 首页>>代码示例>>PHP>>正文


PHP Twig_Node::setNode方法代码示例

本文整理汇总了PHP中Twig_Node::setNode方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Node::setNode方法的具体用法?PHP Twig_Node::setNode怎么用?PHP Twig_Node::setNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Twig_Node的用法示例。


在下文中一共展示了Twig_Node::setNode方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: leaveNode

 /**
  * {@inheritdoc}
  */
 public function leaveNode(Twig_Node $node, Twig_Environment $env)
 {
     if ($node instanceof Twig_Node_Module) {
         $varName = $this->getVarName();
         $node->setNode('display_start', new Twig_Node(array(new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::TEMPLATE, $node->getAttribute('filename'), $varName), $node->getNode('display_start'))));
         $node->setNode('display_end', new Twig_Node(array(new Twig_Profiler_Node_LeaveProfile($varName), $node->getNode('display_end'))));
     } elseif ($node instanceof Twig_Node_Block) {
         $varName = $this->getVarName();
         $node->setNode('body', new Twig_Node_Body(array(new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::BLOCK, $node->getAttribute('name'), $varName), $node->getNode('body'), new Twig_Profiler_Node_LeaveProfile($varName))));
     } elseif ($node instanceof Twig_Node_Macro) {
         $varName = $this->getVarName();
         $node->setNode('body', new Twig_Node_Body(array(new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::MACRO, $node->getAttribute('name'), $varName), $node->getNode('body'), new Twig_Profiler_Node_LeaveProfile($varName))));
     }
     return $node;
 }
开发者ID:rjagadishsingh,项目名称:Twig,代码行数:18,代码来源:Profiler.php

示例2: leaveNode

 /**
  * Called after child nodes are visited.
  *
  * @param Twig_Node        $node The node to visit
  * @param Twig_Environment $env  The Twig environment instance
  *
  * @return Twig_Node The modified node
  */
 public function leaveNode(Twig_Node $node, Twig_Environment $env)
 {
     if ($node instanceof Twig_Node_Module) {
         $this->inAModule = false;
         $node->setNode('display_start', new Twig_Node(array(new Twig_Node_CheckSecurity($this->filters, $this->tags, $this->functions), $node->getNode('display_start'))));
     }
     return $node;
 }
开发者ID:rjagadishsingh,项目名称:Twig,代码行数:16,代码来源:Sandbox.php

示例3: parse

 public function parse(\Twig_Token $token)
 {
     $lineno = $token->getLine();
     $expression = $this->parser->getExpressionParser()->parseExpression();
     $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
     $this->parser->subparse(array($this, 'decideCaseFork'));
     $cases = new \Twig_Node();
     $default = null;
     $end = false;
     $i = 0;
     while (!$end) {
         switch ($tag = $this->parser->getStream()->next()->getValue()) {
             case 'case':
                 $i++;
                 $expr = $this->parser->getExpressionParser()->parseExpression();
                 $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
                 $body = $this->parser->subparse(array($this, 'decideCaseFork'));
                 $cases->setNode($i, new \Twig_Node(array('expression' => $expr, 'body' => $body)));
                 break;
             case 'default':
                 $i = null;
                 $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
                 $body = $this->parser->subparse(array($this, 'decideCaseFork'));
                 $default = $body;
                 break;
             case 'break':
                 $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
                 $this->parser->subparse(array($this, 'decideCaseFork'));
                 if ($cases->hasNode($i)) {
                     $cases->getNode($i)->setAttribute('break', true);
                 }
                 break;
             case 'endswitch':
                 $end = true;
                 break;
             default:
                 throw new \Twig_Error_Syntax(sprintf('Unexpected end of template at line %d' . $tag, $lineno), -1);
         }
     }
     $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
     return new SwitchNode($cases, $default, $expression, $lineno, $this->getTag());
 }
开发者ID:rmaiwald,项目名称:core,代码行数:42,代码来源:SwitchTokenParser.php

示例4: doEnterNode

 /**
  * {@inheritdoc}
  */
 protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env)
 {
     if ($node instanceof \Twig_Node_Block || $node instanceof \Twig_Node_Module) {
         $this->scope = $this->scope->enter();
     }
     if ($node instanceof TransDefaultDomainNode) {
         if ($node->getNode('expr') instanceof \Twig_Node_Expression_Constant) {
             $this->scope->set('domain', $node->getNode('expr'));
             return $node;
         } else {
             $var = $env->getParser()->getVarName();
             $name = new \Twig_Node_Expression_AssignName($var, $node->getLine());
             $this->scope->set('domain', new \Twig_Node_Expression_Name($var, $node->getLine()));
             return new \Twig_Node_Set(false, new \Twig_Node(array($name)), new \Twig_Node(array($node->getNode('expr'))), $node->getLine());
         }
     }
     if (!$this->scope->has('domain')) {
         return $node;
     }
     if ($node instanceof \Twig_Node_Expression_Filter && in_array($node->getNode('filter')->getAttribute('value'), array('trans', 'transchoice'))) {
         $arguments = $node->getNode('arguments');
         $ind = 'trans' === $node->getNode('filter')->getAttribute('value') ? 1 : 2;
         if ($this->isNamedArguments($arguments)) {
             if (!$arguments->hasNode('domain') && !$arguments->hasNode($ind)) {
                 $arguments->setNode('domain', $this->scope->get('domain'));
             }
         } else {
             if (!$arguments->hasNode($ind)) {
                 if (!$arguments->hasNode($ind - 1)) {
                     $arguments->setNode($ind - 1, new \Twig_Node_Expression_Array(array(), $node->getLine()));
                 }
                 $arguments->setNode($ind, $this->scope->get('domain'));
             }
         }
     } elseif ($node instanceof TransNode) {
         if (!$node->hasNode('domain')) {
             $node->setNode('domain', $this->scope->get('domain'));
         }
     }
     return $node;
 }
开发者ID:ayoah,项目名称:symfony,代码行数:44,代码来源:TranslationDefaultDomainNodeVisitor.php

示例5: doLeaveNode

 /**
  * {@inheritdoc}
  */
 protected function doLeaveNode(\Twig_Node $node, \Twig_Environment $env)
 {
     if ($node instanceof \Twig_Node_Module) {
         $this->filename = null;
     }
     if ($this->shouldProcess()) {
         if ($node instanceof \Twig_Node_Module) {
             if ($this->shouldBufferize) {
                 $node->setNode('body', new \Twig_Node(array(new Initialize($this->settings['defaultExecutionPriority']), $node->getNode('body'), new Terminate($this->settings['defaultExecutionPriority']))));
             }
             $this->shouldBufferize = false;
             $this->blocks = array();
         }
         if ($this->isBufferizingNode($node) || $node instanceof \Twig_Node_BlockReference && $this->hasBufferizingNode($this->blocks[$node->getAttribute('name')])) {
             return new \Twig_Node(array(new BufferBreakPoint($this->settings['defaultExecutionPriority']), $node, new BufferBreakPoint($this->settings['defaultExecutionPriority'], array(), array(BaseBufferNode::BUFFERIZED_EXECUTION_PRIORITY_ATTRIBUTE_NAME => $this->getNodeExecutionPriority($node)))));
         } elseif ($this->currentScope && $node instanceof \Twig_Node_Block && $this->hasBufferizingNode($node)) {
             $node->setNode('body', new \Twig_Node(array(new Initialize($this->settings['defaultExecutionPriority']), $node->getNode('body'), new Terminate($this->settings['defaultExecutionPriority']))));
             return $node;
         }
     }
     return $node;
 }
开发者ID:runopencode,项目名称:twig-bufferized-template,代码行数:25,代码来源:NodeVisitor.php

示例6: getTests

    public function getTests()
    {
        $tests = array();
        // #1 switch with one case, without break
        $expression = new \Twig_Node_Expression_Name('foo', 0);
        $default = null;
        $cases = new \Twig_Node();
        $cases->setNode(0, new \Twig_Node(array('expression' => new \Twig_Node_Expression_Constant(0, 0), 'body' => new \Twig_Node_Text('case 0', 0))));
        $node = new SwitchNode($cases, $default, $expression, 0);
        $tests[] = array($node, <<<EOF
switch ({$this->getVariableGetter('foo')}) {
    case 0:
        echo "case 0";
}
EOF
);
        // #2 switch with two cases, second with break
        $expression = new \Twig_Node_Expression_Name('foo', 0);
        $default = null;
        $cases = new \Twig_Node();
        $cases->setNode(0, new \Twig_Node(array('expression' => new \Twig_Node_Expression_Constant(0, 0), 'body' => new \Twig_Node_Text('case 0', 0))));
        $cases->setNode(1, new \Twig_Node(array('expression' => new \Twig_Node_Expression_Constant(1, 0), 'body' => new \Twig_Node_Text('case 1', 0))));
        $cases->getNode(1)->setAttribute('break', true);
        $node = new SwitchNode($cases, $default, $expression, 0);
        $tests[] = array($node, <<<EOF
switch ({$this->getVariableGetter('foo')}) {
    case 0:
        echo "case 0";
    case 1:
        echo "case 1";
        break;
}
EOF
);
        // #3 switch with two cases (second with break) and default
        $expression = new \Twig_Node_Expression_Name('foo', 0);
        $default = new \Twig_Node_Text('default case', 0);
        $cases = new \Twig_Node();
        $cases->setNode(0, new \Twig_Node(array('expression' => new \Twig_Node_Expression_Constant(0, 0), 'body' => new \Twig_Node_Text('case 0', 0))));
        $cases->setNode(1, new \Twig_Node(array('expression' => new \Twig_Node_Expression_Constant(1, 0), 'body' => new \Twig_Node_Text('case 1', 0))));
        $cases->getNode(1)->setAttribute('break', true);
        $node = new SwitchNode($cases, $default, $expression, 0);
        $tests[] = array($node, <<<EOF
switch ({$this->getVariableGetter('foo')}) {
    case 0:
        echo "case 0";
    case 1:
        echo "case 1";
        break;
    default:
        echo "default case";
}
EOF
);
        // #4 switch with two cases (first without body, second with break) and default
        $expression = new \Twig_Node_Expression_Name('foo', 0);
        $default = new \Twig_Node_Text('default case', 0);
        $cases = new \Twig_Node();
        $cases->setNode(0, new \Twig_Node(array('expression' => new \Twig_Node_Expression_Constant(0, 0), 'body' => new \Twig_Node())));
        $cases->setNode(1, new \Twig_Node(array('expression' => new \Twig_Node_Expression_Constant(1, 0), 'body' => new \Twig_Node_Text('case 1', 0))));
        $cases->getNode(1)->setAttribute('break', true);
        $node = new SwitchNode($cases, $default, $expression, 0);
        $tests[] = array($node, <<<EOF
switch ({$this->getVariableGetter('foo')}) {
    case 0:
    case 1:
        echo "case 1";
        break;
    default:
        echo "default case";
}
EOF
);
        return $tests;
    }
开发者ID:Silwereth,项目名称:core,代码行数:75,代码来源:SwitchNodeTest.php


注:本文中的Twig_Node::setNode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。