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


PHP Twig_Node类代码示例

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


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

示例1: visit

 public function visit(Twig_Node $node)
 {
     // autoescape?
     if ($node instanceof Twig_Node_AutoEscape) {
         $this->statusStack[] = $node->getValue();
         $node = $this->visitDeep($node);
         array_pop($this->statusStack);
         // remove the node
         return $node;
     }
     if (!$node instanceof Twig_Node_Print) {
         return $this->visitDeep($node);
     }
     if (false === $this->needEscaping()) {
         return $node;
     }
     $expression = $node->getExpression();
     // don't escape if escape has already been called
     // or if we want the safe string
     if ($expression instanceof Twig_Node_Expression_Filter && ($expression->hasFilter('escape') || $expression->hasFilter('safe'))) {
         return $node;
     }
     // escape
     if ($expression instanceof Twig_Node_Expression_Filter) {
         $expression->appendFilter(array('escape', array()));
         return $node;
     } else {
         return new Twig_Node_Print(new Twig_Node_Expression_Filter($expression, array(array('escape', array())), $node->getLine()), $node->getLine());
     }
 }
开发者ID:vtprepo,项目名称:Twig,代码行数:30,代码来源:Escaper.php

示例2: loadNode

 /**
  * Loads assets from the supplied node.
  *
  * @return array An array of asset formulae indexed by name
  */
 private function loadNode(\Twig_Node $node)
 {
     $formulae = array();
     if ($node instanceof AsseticNode) {
         $formulae[$node->getAttribute('name')] = array($node->getAttribute('inputs'), $node->getAttribute('filters'), array('output' => $node->getAttribute('asset')->getTargetPath(), 'name' => $node->getAttribute('name'), 'debug' => $node->getAttribute('debug'), 'combine' => $node->getAttribute('combine')));
     } elseif ($node instanceof \Twig_Node_Expression_Function) {
         $name = $node->getNode('name')->getAttribute('name');
         if ($this->twig->getFunction($name) instanceof AsseticFilterFunction) {
             $arguments = array();
             foreach ($node->getNode('arguments') as $argument) {
                 $arguments[] = eval('return ' . $this->twig->compile($argument) . ';');
             }
             $invoker = $this->twig->getExtension('assetic')->getFilterInvoker($name);
             $inputs = isset($arguments[0]) ? (array) $arguments[0] : array();
             $filters = $invoker->getFilters();
             $options = array_replace($invoker->getOptions(), isset($arguments[1]) ? $arguments[1] : array());
             if (!isset($options['name'])) {
                 $options['name'] = $invoker->getFactory()->generateAssetName($inputs, $filters, $options);
             }
             $formulae[$options['name']] = array($inputs, $filters, $options);
         }
     }
     foreach ($node as $child) {
         if ($child instanceof \Twig_Node) {
             $formulae += $this->loadNode($child);
         }
     }
     return $formulae;
 }
开发者ID:richardmiller,项目名称:assetic,代码行数:34,代码来源:TwigFormulaLoader.php

示例3: visit

 public function visit(Twig_Node $node)
 {
     // filter?
     if ($node instanceof Twig_Node_Filter) {
         $this->statusStack[] = $node->getFilters();
         $node = $this->visitDeep($node);
         array_pop($this->statusStack);
         return $node;
     }
     if (!$node instanceof Twig_Node_Print && !$node instanceof Twig_Node_Text) {
         return $this->visitDeep($node);
     }
     if (false === ($filters = $this->getCurrentFilters())) {
         return $node;
     }
     if ($node instanceof Twig_Node_Text) {
         $expression = new Twig_Node_Expression_Constant($node->getData(), $node->getLine());
     } else {
         $expression = $node->getExpression();
     }
     // filters
     if ($expression instanceof Twig_Node_Expression_Filter) {
         $expression->appendFilters($filters);
         return $node;
     } else {
         return new Twig_Node_Print(new Twig_Node_Expression_Filter($expression, $filters, $node->getLine()), $node->getLine());
     }
 }
开发者ID:vtprepo,项目名称:Twig,代码行数:28,代码来源:Filter.php

示例4: removeNodeFilter

 /**
  * Removes node filters.
  *
  * This is mostly needed when another visitor adds filters (like the escaper one).
  *
  * @param Twig_Node $node A Node
  */
 protected function removeNodeFilter($node)
 {
     if ($node instanceof Twig_Node_Expression_Filter) {
         return $this->removeNodeFilter($node->getNode('node'));
     }
     return $node;
 }
开发者ID:nickaggarwal,项目名称:sample-symfony2,代码行数:14,代码来源:SandboxedPrint.php

示例5: 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

示例6: isUrlGenerationSafe

 /**
  * Determines at compile time whether the generated URL will be safe and thus
  * saving the unneeded automatic escaping for performance reasons.
  *
  * The URL generation process percent encodes non-alphanumeric characters. So there is no risk
  * that malicious/invalid characters are part of the URL. The only character within an URL that
  * must be escaped in html is the ampersand ("&") which separates query params. So we cannot mark
  * the URL generation as always safe, but only when we are sure there won't be multiple query
  * params. This is the case when there are none or only one constant parameter given.
  * E.g. we know beforehand this will be safe:
  * - path('route')
  * - path('route', {'param': 'value'})
  * But the following may not:
  * - path('route', var)
  * - path('route', {'param': ['val1', 'val2'] }) // a sub-array
  * - path('route', {'param1': 'value1', 'param2': 'value2'})
  * If param1 and param2 reference placeholder in the route, it would still be safe. But we don't know.
  *
  * @param \Twig_Node $argsNode The arguments of the path/url function
  *
  * @return array An array with the contexts the URL is safe
  */
 public function isUrlGenerationSafe(\Twig_Node $argsNode)
 {
     // support named arguments
     $paramsNode = $argsNode->hasNode('parameters') ? $argsNode->getNode('parameters') : ($argsNode->hasNode(1) ? $argsNode->getNode(1) : null);
     if (null === $paramsNode || $paramsNode instanceof \Twig_Node_Expression_Array && count($paramsNode) <= 2 && (!$paramsNode->hasNode(1) || $paramsNode->getNode(1) instanceof \Twig_Node_Expression_Constant)) {
         return array('html');
     }
     return array();
 }
开发者ID:TuxCoffeeCorner,项目名称:tcc,代码行数:31,代码来源:RoutingExtension.php

示例7: leaveNode

 public function leaveNode(Twig_Node $node, Twig_Environment $env)
 {
     if ($node instanceof Twig_Node_Module) {
         $node->setUsedFilters(array_keys($this->filters));
         $node->setUsedTags(array_keys($this->tags));
         $this->inAModule = false;
     }
     return $node;
 }
开发者ID:skoop,项目名称:MediTerra,代码行数:9,代码来源:Sandbox.php

示例8: getVariables

 /**
  * Find placeholder nodes recursively.
  *
  * @param Twig_Node $node
  * @param array $placeholders
  */
 protected function getVariables($node, &$placeholders)
 {
     if ($node instanceof Curry_Twig_Node_Placeholder) {
         $placeholders[$node->getAttribute('name')] = true;
     }
     foreach ($node->getIterator() as $n) {
         if ($n instanceof Twig_Node) {
             $this->getVariables($n, $placeholders);
         }
     }
 }
开发者ID:varvanin,项目名称:currycms,代码行数:17,代码来源:Module.php

示例9: compileString

 protected function compileString(\Twig_Node $body)
 {
     if ($body instanceof \Twig_Node_Expression_Constant) {
         $msg = $body->getAttribute('value');
     } elseif ($body instanceof \Twig_Node_Text) {
         $msg = $body->getAttribute('data');
     } else {
         return $body;
     }
     return new \Twig_Node_Expression_Constant(trim($msg), $body->getLine());
 }
开发者ID:hexmedia,项目名称:content-bundle,代码行数:11,代码来源:AreaNode.php

示例10: doLeaveNode

 protected function doLeaveNode(\Twig_Node $node, \Twig_Environment $env)
 {
     if ($node instanceof \Twig_Node_Include) {
         if ($node->hasNode('expr') && $node->getNode('expr')->hasAttribute('value')) {
             $patternStoreKey = $node->getNode('expr')->getAttribute('value');
             $data = Data::getPatternSpecificData($patternStoreKey);
             $dataNode = new PatternDataIncludeNode($node, $data);
             return $dataNode;
         }
     }
     return $node;
 }
开发者ID:aleksip,项目名称:patternengine-php-twig,代码行数:12,代码来源:IncludeNodeVisitor.php

示例11: __construct

 public function __construct(Twig_Node $node, Twig_Node_Expression_Constant $filterName, Twig_Node $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);
 }
开发者ID:PieterSwitten,项目名称:webandmobile,代码行数:12,代码来源:Default.php

示例12: __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

示例13: visitDeep

 protected function visitDeep(Twig_Node $node)
 {
     if (!$node instanceof Twig_NodeListInterface) {
         return $node;
     }
     $newNodes = array();
     foreach ($nodes = $node->getNodes() as $k => $n) {
         if (null !== ($n = $this->visit($n))) {
             $newNodes[$k] = $n;
         }
     }
     $node->setNodes($newNodes);
     return $node;
 }
开发者ID:vtprepo,项目名称:Twig,代码行数:14,代码来源:NodeTransformer.php

示例14: __construct

 public function __construct(\Twig_Node $left, \Twig_Node $right, $lineno)
 {
     parent::__construct(array('left' => $left, 'right' => $right), array(), $lineno);
     if ($left instanceof \Twig_Node_Expression_Name) {
         $this->arguments = [$left->getAttribute('name')];
     } elseif ($left instanceof Arguments) {
         $this->arguments = $left->getArguments();
     } else {
         throw new \InvalidArgumentException('Invalid argument\'s list for lambda.');
     }
     if (count($this->arguments) !== count(array_flip($this->arguments))) {
         throw new \InvalidArgumentException('Each lambda argument must have unique name.');
     }
 }
开发者ID:dpolac,项目名称:twig-lambda,代码行数:14,代码来源:LambdaWithArguments.php

示例15: __construct

 public function __construct($count, Twig_NodeList $body, $plural, $lineno, $tag = null)
 {
     parent::__construct($lineno, $tag);
     $this->count = $count;
     $this->body = $body;
     $this->plural = $plural;
 }
开发者ID:skoop,项目名称:MediTerra,代码行数:7,代码来源:Trans.php


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