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


PHP Twig_Node::setAttribute方法代码示例

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


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

示例1: __construct

 public function __construct(Twig_Node $node, $name, Twig_Node $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 instanceof Twig_Node_Expression_GetProperty || $node instanceof Twig_Node_Expression_MethodCall) {
         $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);
 }
开发者ID:superdav42,项目名称:Twig,代码行数:14,代码来源:Defined.php

示例2: doLeaveNode

 protected function doLeaveNode(\Twig_Node $node, \Twig_Environment $env)
 {
     if ($node instanceof WhitespaceCollapse || $node instanceof \Twig_Node_Block || $node instanceof \Twig_Node_AutoEscape) {
         array_pop($this->statusStack);
     } elseif ($node instanceof \Twig_Node_BlockReference) {
         $this->blocks[$node->getAttribute('name')] = $this->needCollapsing();
     } elseif ($node instanceof \Twig_Node_Text && $this->needCollapsing()) {
         $text = $node->getAttribute('data');
         if ($this->previousNode instanceof \Twig_Node_Text && ctype_space(substr($this->previousNode->getAttribute('data'), -1))) {
             $text = ltrim($text);
         }
         if ($text === '') {
             return false;
         }
         $node->setAttribute('data', preg_replace(array('/\\s{2,}/', '/<\\s/', '/\\s>/'), array(' ', '<', '>'), $text));
     }
     $this->previousNode = $node;
     return $node;
 }
开发者ID:matthecat,项目名称:twig-whitespace-collapse-extension,代码行数:19,代码来源:WhitespaceCollapser.php

示例3: enterOptimizeFor

 /**
  * Optimizes "for" tag by removing the "loop" variable creation whenever possible.
  *
  * @param Twig_Node        $node A Node
  * @param Twig_Environment $env  The current Twig environment
  */
 protected function enterOptimizeFor(Twig_Node $node, Twig_Environment $env)
 {
     if ($node instanceof Twig_Node_For) {
         // disable the loop variable by default
         $node->setAttribute('with_loop', false);
         array_unshift($this->loops, $node);
         array_unshift($this->loopsTargets, $node->getNode('value_target')->getAttribute('name'));
         array_unshift($this->loopsTargets, $node->getNode('key_target')->getAttribute('name'));
     } elseif (!$this->loops) {
         // we are outside a loop
         return;
     } elseif ($node instanceof Twig_Node_Expression_Name && 'loop' === $node->getAttribute('name')) {
         $node->setAttribute('always_defined', true);
         $this->addLoopToCurrent();
     } elseif ($node instanceof Twig_Node_Expression_Name && in_array($node->getAttribute('name'), $this->loopsTargets)) {
         $node->setAttribute('always_defined', true);
     } elseif ($node instanceof Twig_Node_BlockReference || $node instanceof Twig_Node_Expression_BlockReference) {
         $this->addLoopToCurrent();
     } elseif ($node instanceof Twig_Node_Include && !$node->getAttribute('only')) {
         $this->addLoopToAll();
     } elseif ($node instanceof Twig_Node_Expression_Function && 'include' === $node->getAttribute('name') && (!$node->getNode('arguments')->hasNode('with_context') || false !== $node->getNode('arguments')->getNode('with_context')->getAttribute('value'))) {
         $this->addLoopToAll();
     } elseif ($node instanceof Twig_Node_Expression_GetAttr && (!$node->getNode('attribute') instanceof Twig_Node_Expression_Constant || 'parent' === $node->getNode('attribute')->getAttribute('value')) && (true === $this->loops[0]->getAttribute('with_loop') || $node->getNode('node') instanceof Twig_Node_Expression_Name && 'loop' === $node->getNode('node')->getAttribute('name'))) {
         $this->addLoopToAll();
     }
 }
开发者ID:rafasashi,项目名称:Twig,代码行数:32,代码来源:Optimizer.php

示例4: enterNode

 public function enterNode(Twig_Node $node, Twig_Environment $env)
 {
     if ($node instanceof Twig_Node_Expression_GetAttr) {
         $node->setAttribute('disable_c_ext', true);
     }
     return $node;
 }
开发者ID:freeztime,项目名称:ignitedcms-pro,代码行数:7,代码来源:TemplateTest.php


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