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


PHP Twig_Node::hasNode方法代码示例

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


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

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

示例2: getReadDomainFromArguments

 /**
  * @param \Twig_Node $arguments
  * @param int        $index
  *
  * @return string|null
  */
 private function getReadDomainFromArguments(\Twig_Node $arguments, $index)
 {
     if ($arguments->hasNode('domain')) {
         $argument = $arguments->getNode('domain');
     } elseif ($arguments->hasNode($index)) {
         $argument = $arguments->getNode($index);
     } else {
         return null;
     }
     return $this->getReadDomainFromNode($argument);
 }
开发者ID:TuxCoffeeCorner,项目名称:tcc,代码行数:17,代码来源:TranslationNodeVisitor.php

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

示例4: 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 = $this->dt->getProcessedPatternSpecificData($patternStoreKey);
             if ($node instanceof \Twig_Node_Embed) {
                 $dataNode = new PatternDataEmbedNode($node, $data);
             } else {
                 $dataNode = new PatternDataIncludeNode($node, $data);
             }
             return $dataNode;
         }
     }
     return $node;
 }
开发者ID:aleksip,项目名称:plugin-data-transform,代码行数:16,代码来源:PatternDataNodeVisitor.php

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

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

示例7: isUrlGenerationSafe

 /**
  * Determines at compile time whether the generated URL will be safe.
  *
  * Saves the unneeded automatic escaping for performance reasons.
  *
  * The URL generation process percent encodes non-alphanumeric characters.
  * Thus, the only character within a URL that must be escaped in HTML is the
  * ampersand ("&") which separates query params. Thus we cannot mark
  * the generated URL 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. For instance, we know beforehand this will not
  * need to be escaped:
  * - path('route')
  * - path('route', {'param': 'value'})
  * But the following may need to be escaped:
  * - path('route', var)
  * - path('route', {'param': ['val1', 'val2'] }) // a sub-array
  * - path('route', {'param1': 'value1', 'param2': 'value2'})
  * If param1 and param2 reference placeholders in the route, it would not
  * need to be escaped, but we don't know that in advance.
  *
  * @param \Twig_Node $args_node
  *   The arguments of the path/url functions.
  *
  * @return array
  *   An array with the contexts the URL is safe
  */
 public function isUrlGenerationSafe(\Twig_Node $args_node)
 {
     // Support named arguments.
     $parameter_node = $args_node->hasNode('parameters') ? $args_node->getNode('parameters') : ($args_node->hasNode(1) ? $args_node->getNode(1) : NULL);
     if (!isset($parameter_node) || $parameter_node instanceof \Twig_Node_Expression_Array && count($parameter_node) <= 2 && (!$parameter_node->hasNode(1) || $parameter_node->getNode(1) instanceof \Twig_Node_Expression_Constant)) {
         return array('html');
     }
     return array();
 }
开发者ID:Greg-Boggs,项目名称:electric-dev,代码行数:36,代码来源:TwigExtension.php

示例8: _extractMessage

    /**
     * Extract a message from a \Twig_Node_Print
     * Return null if not a constant message
     *
     * @param \Twig_Node $node
     */
    private function _extractMessage(\Twig_Node $node)
    {
        if($node->hasNode('node')) {
            return $this->_extractMessage($node->getNode ('node'));
        }
        if($node instanceof \Twig_Node_Expression_Constant) {
            return $node->getAttribute('value');
        }

        return null;
    }
开发者ID:rubensayshi,项目名称:BCCExtraToolsBundle,代码行数:17,代码来源:UpdateTransCommand.php

示例9: getNode

 /**
  * @param \Twig_Node $node
  * @param $name
  * @return null|\Twig_Node
  */
 public function getNode(\Twig_Node $node, $name)
 {
     return $node->hasNode($name) ? $node->getNode($name) : null;
 }
开发者ID:selmanouni,项目名称:blue-lines,代码行数:9,代码来源:TwigDataExtractor.php


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