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


PHP Twig_Node_Expression_Array类代码示例

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


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

示例1: compileString

 protected function compileString(\Twig_NodeInterface $body, \Twig_Node_Expression_Array $vars)
 {
     if ($body instanceof \Twig_Node_Expression_Constant) {
         $msg = $body->getAttribute('value');
     } elseif ($body instanceof \Twig_Node_Text) {
         $msg = $body->getAttribute('data');
     } else {
         return array($body, $vars);
     }
     preg_match_all('/(?<!%)%([^%]+)%/', $msg, $matches);
     if (version_compare(\Twig_Environment::VERSION, '1.5', '>=')) {
         foreach ($matches[1] as $var) {
             $key = new \Twig_Node_Expression_Constant('%' . $var . '%', $body->getLine());
             if (!$vars->hasElement($key)) {
                 $vars->addElement(new \Twig_Node_Expression_Name($var, $body->getLine()), $key);
             }
         }
     } else {
         $current = array();
         foreach ($vars as $name => $var) {
             $current[$name] = true;
         }
         foreach ($matches[1] as $var) {
             if (!isset($current['%' . $var . '%'])) {
                 $vars->setNode('%' . $var . '%', new \Twig_Node_Expression_Name($var, $body->getLine()));
             }
         }
     }
     return array(new \Twig_Node_Expression_Constant(str_replace('%%', '%', trim($msg)), $body->getLine()), $vars);
 }
开发者ID:miguelibero,项目名称:meinhof,代码行数:30,代码来源:TransNode.php

示例2: parse

 public function parse(\Twig_Token $token)
 {
     $lineno = $token->getLine();
     $stream = $this->parser->getStream();
     $resources = new \Twig_Node_Expression_Array(array(), $stream->getCurrent()->getLine());
     do {
         $resources->addElement($this->parser->getExpressionParser()->parseExpression());
     } while (!$stream->test(\Twig_Token::BLOCK_END_TYPE));
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     return new GitThemeNode($resources, $lineno, $this->getTag());
 }
开发者ID:gitonomy,项目名称:git-bundle,代码行数:11,代码来源:GitThemeTokenParser.php

示例3: valueNode

 public function valueNode()
 {
     // date value (either a DateTime object, or null)
     $valueNode = parent::valueNode();
     // format('Y-m-d') method call on date object
     $args = new \Twig_Node_Expression_Array([], $this->lineno);
     $args->addElement(new \Twig_Node_Expression_Constant('j M, Y', $this->lineno));
     $formatNode = new \Twig_Node_Expression_MethodCall($valueNode, 'format', $args, $this->lineno);
     // conditional to check for a null value
     $conditionalNode = new \Twig_Node_Expression_Conditional($valueNode, $formatNode, $valueNode, $this->lineno);
     return $conditionalNode;
 }
开发者ID:fierce,项目名称:fierce,代码行数:12,代码来源:DateFieldNode.php

示例4: convertToViewArguments

 protected function convertToViewArguments(\Twig_Node_Expression_Array $array)
 {
     $arguments = array();
     foreach (array_chunk($array->getIterator()->getArrayCopy(), 2) as $pair) {
         if (count($pair) == 2) {
             $key = $pair[0]->getAttribute('value');
             $value = $pair[1]->getAttribute('value');
             // @todo support for multiple types
             $arguments[$key] = $value;
         }
     }
     return $arguments;
 }
开发者ID:LeonB,项目名称:site,代码行数:13,代码来源:twig_setcontent.php

示例5: escapeContextVariables

 /**
  * @param  string                      $msg
  * @param  \Twig_Node_Expression_Array $vars
  * @param  int                         $lineno
  * @return \Twig_Node_Expression_Array
  */
 protected function escapeContextVariables($msg, $vars, $lineno)
 {
     preg_match_all('/(?<!%)%([^%]+)%/', $msg, $matches);
     foreach ($matches[1] as $var) {
         $key = new \Twig_Node_Expression_Constant('%' . $var . '%', $lineno);
         if (!$vars->hasElement($key)) {
             $node = new \Twig_Node_Expression_Name($var, $lineno);
             $node = $this->escapeNodeIfNecessary($node, $lineno);
             $vars->addElement($node, $key);
         }
     }
     return $vars;
 }
开发者ID:arthens,项目名称:safe-translations,代码行数:19,代码来源:SafeTransNode.php

示例6: getTests

 public function getTests()
 {
     $tests = array();
     $expr = new Twig_Node_Expression_Name('foo', 1);
     $attr = new Twig_Node_Expression_Constant('bar', 1);
     $args = new Twig_Node_Expression_Array(array(), 1);
     $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::ANY_CALL, 1);
     $tests[] = array($node, sprintf('%s%s, "bar", [])', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1)));
     $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::ARRAY_CALL, 1);
     $tests[] = array($node, sprintf('%s%s, "bar", [], "array")', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1)));
     $args = new Twig_Node_Expression_Array(array(), 1);
     $args->addElement(new Twig_Node_Expression_Name('foo', 1));
     $args->addElement(new Twig_Node_Expression_Constant('bar', 1));
     $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::METHOD_CALL, 1);
     $tests[] = array($node, sprintf('%s%s, "bar", [0 => %s, 1 => "bar"], "method")', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1), $this->getVariableGetter('foo')));
     return $tests;
 }
开发者ID:rjagadishsingh,项目名称:Twig,代码行数:17,代码来源:GetAttrTest.php

示例7: parse

 /**
  * {@inheritdoc}
  */
 public function parse(\Twig_Token $token)
 {
     $lineno = $token->getLine();
     $stream = $this->parser->getStream();
     $datagrid = $this->parser->getExpressionParser()->parseExpression();
     if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'with')) {
         $this->parser->getStream()->next();
         $resources = $this->parser->getExpressionParser()->parseExpression();
     } else {
         $resources = new \Twig_Node_Expression_Array([], $stream->getCurrent()->getLine());
         do {
             $resources->addElement($this->parser->getExpressionParser()->parseExpression());
         } while (!$stream->test(\Twig_Token::BLOCK_END_TYPE));
     }
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     return new DatagridThemeNode($datagrid, $resources, $lineno, $this->getTag());
 }
开发者ID:rollerworks,项目名称:datagrid-twig,代码行数:20,代码来源:DatagridThemeTokenParser.php

示例8: enterNode

 /**
  * @param \Twig_NodeInterface $node
  * @param \Twig_Environment $env
  * @return \Twig_NodeInterface
  */
 public function enterNode(\Twig_NodeInterface $node, \Twig_Environment $env)
 {
     if (!$this->enabled) {
         return $node;
     }
     if ($node instanceof \Twig_Node_Expression_Filter && 'desc' === $node->getNode('filter')->getAttribute('value')) {
         $transNode = $node->getNode('node');
         while ($transNode instanceof \Twig_Node_Expression_Filter && 'trans' !== $transNode->getNode('filter')->getAttribute('value') && 'transchoice' !== $transNode->getNode('filter')->getAttribute('value')) {
             $transNode = $transNode->getNode('node');
         }
         if (!$transNode instanceof \Twig_Node_Expression_Filter) {
             throw new RuntimeException(sprintf('The "desc" filter must be applied after a "trans", or "transchoice" filter.'));
         }
         $wrappingNode = $node->getNode('node');
         $testNode = clone $wrappingNode;
         $defaultNode = $node->getNode('arguments')->getNode(0);
         // if the |transchoice filter is used, delegate the call to the TranslationExtension
         // so that we can catch a possible exception when the default translation has not yet
         // been extracted
         if ('transchoice' === $transNode->getNode('filter')->getAttribute('value')) {
             $transchoiceArguments = new \Twig_Node_Expression_Array(array(), $transNode->getLine());
             $transchoiceArguments->addElement($wrappingNode->getNode('node'));
             $transchoiceArguments->addElement($defaultNode);
             foreach ($wrappingNode->getNode('arguments') as $arg) {
                 $transchoiceArguments->addElement($arg);
             }
             $transchoiceNode = new \Twig_Node_Expression_MethodCall(new \Twig_Node_Expression_ExtensionReference('jms_translation', $transNode->getLine()), 'transchoiceWithDefault', $transchoiceArguments, $transNode->getLine());
             $node->setNode('node', $transchoiceNode);
             return $node;
         }
         // if the |trans filter has replacements parameters
         // (e.g. |trans({'%foo%': 'bar'}))
         if ($wrappingNode->getNode('arguments')->hasNode(0)) {
             $lineno = $wrappingNode->getLine();
             // remove the replacements from the test node
             $testNode->setNode('arguments', clone $testNode->getNode('arguments'));
             $testNode->getNode('arguments')->setNode(0, new \Twig_Node_Expression_Array(array(), $lineno));
             // wrap the default node in a |replace filter
             $defaultNode = new \Twig_Node_Expression_Filter(clone $node->getNode('arguments')->getNode(0), new \Twig_Node_Expression_Constant('replace', $lineno), new \Twig_Node(array(clone $wrappingNode->getNode('arguments')->getNode(0))), $lineno);
         }
         $condition = new \Twig_Node_Expression_Conditional(new \Twig_Node_Expression_Binary_Equal($testNode, $transNode->getNode('node'), $wrappingNode->getLine()), $defaultNode, clone $wrappingNode, $wrappingNode->getLine());
         $node->setNode('node', $condition);
     }
     return $node;
 }
开发者ID:clytemnestra,项目名称:JMSTranslationBundle,代码行数:50,代码来源:DefaultApplyingNodeVisitor.php

示例9: compileString

 protected function compileString(\Twig_NodeInterface $body, \Twig_Node_Expression_Array $vars)
 {
     if ($body instanceof \Twig_Node_Expression_Constant) {
         $msg = $body->getAttribute('value');
     } elseif ($body instanceof \Twig_Node_Text) {
         $msg = $body->getAttribute('data');
     } else {
         return array($body, $vars);
     }
     preg_match_all('/(?<!%)%([^%]+)%/', $msg, $matches);
     foreach ($matches[1] as $var) {
         $key = new \Twig_Node_Expression_Constant('%' . $var . '%', $body->getLine());
         if (!$vars->hasElement($key)) {
             $vars->addElement(new \Twig_Node_Expression_Name($var, $body->getLine()), $key);
         }
     }
     return array(new \Twig_Node_Expression_Constant(str_replace('%%', '%', trim($msg)), $body->getLine()), $vars);
 }
开发者ID:TuxCoffeeCorner,项目名称:tcc,代码行数:18,代码来源:TransNode.php

示例10: parseArguments

 /**
  * @param \Twig_Token $token
  * @return array
  */
 protected function parseArguments(\Twig_Token $token)
 {
     $stream = $this->parser->getStream();
     $location = null;
     if ($stream->nextIf(\Twig_Token::OPERATOR_TYPE, 'in')) {
         $location = $this->parser->getExpressionParser()->parseExpression();
     } else {
         $lineno = $token->getLine();
         $location = new \Twig_Node_Expression_Constant('head', $lineno);
     }
     if ($stream->nextIf(\Twig_Token::NAME_TYPE, 'with')) {
         $variables = $this->parser->getExpressionParser()->parseExpression();
     } else {
         $lineno = $token->getLine();
         $variables = new \Twig_Node_Expression_Array([], $lineno);
         $variables->setAttribute('priority', 0);
     }
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     return [$location, $variables];
 }
开发者ID:ericssonm,项目名称:JusCuzCustoms,代码行数:24,代码来源:TokenParserAssets.php

示例11: compileString

 protected function compileString(\Twig_NodeInterface $body, \Twig_Node_Expression_Array $vars)
 {
     if ($body instanceof \Twig_Node_Expression_Constant) {
         $msg = $body->getAttribute('value');
     } elseif ($body instanceof \Twig_Node_Text) {
         $msg = $body->getAttribute('data');
     } else {
         return array($body, $vars);
     }
     $current = array();
     foreach ($vars as $name => $var) {
         $current[$name] = true;
     }
     preg_match_all('/\\%([^\\%]+)\\%/', $msg, $matches);
     foreach ($matches[1] as $var) {
         if (!isset($current['%' . $var . '%'])) {
             $vars->setNode('%' . $var . '%', new \Twig_Node_Expression_Name($var, $body->getLine()));
         }
     }
     return array(new \Twig_Node_Expression_Constant(trim($msg), $body->getLine()), $vars);
 }
开发者ID:nickaggarwal,项目名称:sample-symfony2,代码行数:21,代码来源:TransNode.php

示例12: parse

 public function parse(\Twig_Token $token)
 {
     $lineno = $token->getLine();
     $arguments = new \Twig_Node_Expression_Array(array(), $lineno);
     $wherearguments = null;
     // name - the new variable with the results
     $name = $this->parser->getStream()->expect(\Twig_Token::NAME_TYPE)->getValue();
     $this->parser->getStream()->expect(\Twig_Token::OPERATOR_TYPE, '=');
     // contenttype, or simple expression to content.
     $contenttype = $this->parser->getExpressionParser()->parseExpression();
     $counter = 0;
     do {
         // where parameter
         if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'where')) {
             $this->parser->getStream()->next();
             $wherearguments = $this->parser->getExpressionParser()->parseExpression();
         }
         // limit parameter
         if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'limit')) {
             $this->parser->getStream()->next();
             $limit = $this->parser->getExpressionParser()->parseExpression();
             $arguments->addElement($limit, new \Twig_Node_Expression_Constant('limit', $lineno));
         }
         // order / orderby parameter
         if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'order') || $this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'orderby')) {
             $this->parser->getStream()->next();
             $order = $this->parser->getExpressionParser()->parseExpression();
             $arguments->addElement($order, new \Twig_Node_Expression_Constant('order', $lineno));
         }
         // paging / allowpaging parameter
         if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'paging') || $this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'allowpaging')) {
             $this->parser->getStream()->next();
             $arguments->addElement(new \Twig_Node_Expression_Constant(true, $lineno), new \Twig_Node_Expression_Constant('paging', $lineno));
         }
         // printquery parameter
         if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'printquery')) {
             $this->parser->getStream()->next();
             $arguments->addElement(new \Twig_Node_Expression_Constant(true, $lineno), new \Twig_Node_Expression_Constant('printquery', $lineno));
         }
         // returnsingle parameter
         if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'returnsingle')) {
             $this->parser->getStream()->next();
             $arguments->addElement(new \Twig_Node_Expression_Constant(true, $lineno), new \Twig_Node_Expression_Constant('returnsingle', $lineno));
         }
         // nohydrate parameter
         if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'nohydrate')) {
             $this->parser->getStream()->next();
             $arguments->addElement(new \Twig_Node_Expression_Constant(false, $lineno), new \Twig_Node_Expression_Constant('hydrate', $lineno));
         }
         // Make sure we don't get stuck in a loop, if a token can't be parsed.
         $counter++;
     } while (!$this->parser->getStream()->test(\Twig_Token::BLOCK_END_TYPE) && $counter < 10);
     $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
     return new SetcontentNode($name, $contenttype, $arguments, $wherearguments, $lineno, $this->getTag());
 }
开发者ID:aleksabp,项目名称:bolt,代码行数:55,代码来源:SetcontentTokenParser.php

示例13: compileString

 protected function compileString(\Twig_NodeInterface $body, \Twig_Node_Expression_Array $vars, $ignoreStrictCheck = false)
 {
     if ($body instanceof \Twig_Node_Expression_Constant) {
         $msg = $body->getAttribute('value');
     } elseif ($body instanceof \Twig_Node_Text) {
         $msg = $body->getAttribute('data');
     } else {
         return array($body, $vars);
     }
     preg_match_all('/(?<!%)%([^%]+)%/', $msg, $matches);
     foreach ($matches[1] as $var) {
         $key = new \Twig_Node_Expression_Constant('%' . $var . '%', $body->getLine());
         if (!$vars->hasElement($key)) {
             if ('count' === $var && null !== $this->getNode('count')) {
                 $vars->addElement($this->getNode('count'), $key);
             } else {
                 $varExpr = new \Twig_Node_Expression_Name($var, $body->getLine());
                 $varExpr->setAttribute('ignore_strict_check', $ignoreStrictCheck);
                 $vars->addElement($varExpr, $key);
             }
         }
     }
     return array(new \Twig_Node_Expression_Constant(str_replace('%%', '%', trim($msg)), $body->getLine()), $vars);
 }
开发者ID:neteasy-work,项目名称:hkgbf_crm,代码行数:24,代码来源:TransNode.php

示例14: parseSubscriptExpression

 public function parseSubscriptExpression($node)
 {
     $stream = $this->parser->getStream();
     $token = $stream->next();
     $lineno = $token->getLine();
     $arguments = new Twig_Node_Expression_Array(array(), $lineno);
     $type = Twig_Template::ANY_CALL;
     if ($token->getValue() == '.') {
         $token = $stream->next();
         if ($token->getType() == Twig_Token::NAME_TYPE || $token->getType() == Twig_Token::NUMBER_TYPE || $token->getType() == Twig_Token::OPERATOR_TYPE && preg_match(Twig_Lexer::REGEX_NAME, $token->getValue())) {
             $arg = new Twig_Node_Expression_Constant($token->getValue(), $lineno);
             if ($stream->test(Twig_Token::PUNCTUATION_TYPE, '(')) {
                 $type = Twig_TemplateInterface::METHOD_CALL;
                 foreach ($this->parseArguments() as $n) {
                     $arguments->addElement($n);
                 }
             }
         } else {
             throw new Twig_Error_Syntax('Expected name or number', $lineno, $this->parser->getFilename());
         }
         if ($node instanceof Twig_Node_Expression_Name && null !== $this->parser->getImportedSymbol('template', $node->getAttribute('name'))) {
             if (!$arg instanceof Twig_Node_Expression_Constant) {
                 throw new Twig_Error_Syntax(sprintf('Dynamic macro names are not supported (called on "%s")', $node->getAttribute('name')), $token->getLine(), $this->parser->getFilename());
             }
             $node = new Twig_Node_Expression_MethodCall($node, 'get' . $arg->getAttribute('value'), $arguments, $lineno);
             $node->setAttribute('safe', true);
             return $node;
         }
     } else {
         $type = Twig_Template::ARRAY_CALL;
         // slice?
         $slice = false;
         if ($stream->test(Twig_Token::PUNCTUATION_TYPE, ':')) {
             $slice = true;
             $arg = new Twig_Node_Expression_Constant(0, $token->getLine());
         } else {
             $arg = $this->parseExpression();
         }
         if ($stream->nextIf(Twig_Token::PUNCTUATION_TYPE, ':')) {
             $slice = true;
         }
         if ($slice) {
             if ($stream->test(Twig_Token::PUNCTUATION_TYPE, ']')) {
                 $length = new Twig_Node_Expression_Constant(null, $token->getLine());
             } else {
                 $length = $this->parseExpression();
             }
             $class = $this->getFilterNodeClass('slice', $token->getLine());
             $arguments = new Twig_Node(array($arg, $length));
             $filter = new $class($node, new Twig_Node_Expression_Constant('slice', $token->getLine()), $arguments, $token->getLine());
             $stream->expect(Twig_Token::PUNCTUATION_TYPE, ']');
             return $filter;
         }
         $stream->expect(Twig_Token::PUNCTUATION_TYPE, ']');
     }
     return new Twig_Node_Expression_GetAttr($node, $arg, $arguments, $type, $lineno);
 }
开发者ID:dev-lav,项目名称:htdocs,代码行数:57,代码来源:ExpressionParser.php

示例15: parseSubscriptExpression

 public function parseSubscriptExpression($node)
 {
     $stream = $this->parser->getStream();
     $token = $stream->next();
     $lineno = $token->getLine();
     $arguments = new Twig_Node_Expression_Array(array(), $lineno);
     $type = Twig_TemplateInterface::ANY_CALL;
     if ($token->getValue() == '.') {
         $token = $stream->next();
         if ($token->getType() == Twig_Token::NAME_TYPE || $token->getType() == Twig_Token::NUMBER_TYPE || $token->getType() == Twig_Token::OPERATOR_TYPE && preg_match(Twig_Lexer::REGEX_NAME, $token->getValue())) {
             $arg = new Twig_Node_Expression_Constant($token->getValue(), $lineno);
             if ($stream->test(Twig_Token::PUNCTUATION_TYPE, '(')) {
                 $type = Twig_TemplateInterface::METHOD_CALL;
                 foreach ($this->parseArguments() as $n) {
                     $arguments->addElement($n);
                 }
             }
         } else {
             throw new Twig_Error_Syntax('Expected name or number', $lineno);
         }
     } else {
         $type = Twig_TemplateInterface::ARRAY_CALL;
         $arg = $this->parseExpression();
         // slice?
         if ($stream->test(Twig_Token::PUNCTUATION_TYPE, ':')) {
             $stream->next();
             if ($stream->test(Twig_Token::PUNCTUATION_TYPE, ']')) {
                 $length = new Twig_Node_Expression_Constant(null, $token->getLine());
             } else {
                 $length = $this->parseExpression();
             }
             $class = $this->getFilterNodeClass('slice');
             $arguments = new Twig_Node(array($arg, $length));
             $filter = new $class($node, new Twig_Node_Expression_Constant('slice', $token->getLine()), $arguments, $token->getLine());
             $stream->expect(Twig_Token::PUNCTUATION_TYPE, ']');
             return $filter;
         }
         $stream->expect(Twig_Token::PUNCTUATION_TYPE, ']');
     }
     return new Twig_Node_Expression_GetAttr($node, $arg, $arguments, $type, $lineno);
 }
开发者ID:Zyko0,项目名称:Baikal,代码行数:41,代码来源:ExpressionParser.php


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