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


PHP Twig_Token类代码示例

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


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

示例1: parse

 /**
  * Parses a token and returns a node.
  *
  * @param  \Twig_Token $token A Twig_Token instance
  *
  * @return \Twig_NodeInterface A Twig_NodeInterface instance
  */
 public function parse(\Twig_Token $token)
 {
     $lineno = $token->getLine();
     $stream = $this->parser->getStream();
     $vars = new \Twig_Node_Expression_Array(array(), $lineno);
     $body = null;
     $count = $this->parser->getExpressionParser()->parseExpression();
     $domain = new \Twig_Node_Expression_Constant('messages', $lineno);
     if (!$stream->test(\Twig_Token::BLOCK_END_TYPE) && $stream->test('for')) {
         // {% transchoice count for "message" %}
         // {% transchoice count for message %}
         $stream->next();
         $body = $this->parser->getExpressionParser()->parseExpression();
     }
     if ($stream->test('with')) {
         // {% transchoice count with vars %}
         $stream->next();
         $vars = $this->parser->getExpressionParser()->parseExpression();
     }
     if ($stream->test('from')) {
         // {% transchoice count from "messages" %}
         $stream->next();
         $domain = $this->parser->getExpressionParser()->parseExpression();
     }
     if (null === $body) {
         // {% transchoice count %}message{% endtranschoice %}
         $stream->expect(\Twig_Token::BLOCK_END_TYPE);
         $body = $this->parser->subparse(array($this, 'decideTransChoiceFork'), true);
     }
     if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
         throw new \Twig_Error_Syntax(sprintf('A message must be a simple text (line %s)', $lineno), -1);
     }
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     return new TransNode($body, $domain, $count, $vars, $lineno, $this->getTag());
 }
开发者ID:hellovic,项目名称:symfony,代码行数:42,代码来源:TransChoiceTokenParser.php

示例2: parse

 public function parse(Twig_Token $token)
 {
     $lineno = $token->getLine();
     $arguments = array();
     // 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();
     if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'where')) {
         $this->parser->getStream()->next();
         $where = $this->parser->getExpressionParser()->parseHashExpression();
         $arguments = $this->convertToViewArguments($where);
     }
     if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'limit')) {
         $this->parser->getStream()->next();
         $limit = $this->parser->getExpressionParser()->parsePrimaryExpression()->getAttribute('value');
         $arguments['limit'] = $limit;
     }
     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()->parsePrimaryExpression()->getAttribute('value');
         $arguments['order'] = $order;
     }
     if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'paging') || $this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'allowpaging')) {
         $this->parser->getStream()->next();
         $arguments['paging'] = true;
     }
     $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
     return new Bolt_Setcontent_Node($name, $contenttype, $arguments, $lineno, $this->getTag());
 }
开发者ID:LeonB,项目名称:site,代码行数:31,代码来源:twig_setcontent.php

示例3: parse

 /**
  * Parses a token and returns a node.
  *
  * @param \Twig_Token $token A Twig_Token instance
  *
  * @return \Twig_NodeInterface A Twig_NodeInterface instance
  */
 public function parse(\Twig_Token $token)
 {
     $expr = $this->parser->getExpressionParser()->parseExpression();
     $stream = $this->parser->getStream();
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     return new \phpbb\template\twig\node\includejs($expr, $this->parser->getEnvironment(), $token->getLine(), $this->getTag());
 }
开发者ID:Tarendai,项目名称:spring-website,代码行数:14,代码来源:includejs.php

示例4: parse

 /**
  * Parses a token and returns a node.
  *
  * @param Twig_Token $token A Twig_Token instance
  *
  * @return Twig_NodeInterface A Twig_NodeInterface instance
  */
 public function parse(Twig_Token $token)
 {
     $lineno = $token->getLine();
     $targets = $this->parser->getExpressionParser()->parseAssignmentExpression();
     $this->parser->getStream()->expect(Twig_Token::OPERATOR_TYPE, 'in');
     $seq = $this->parser->getExpressionParser()->parseExpression();
     $withLoop = true;
     if ($this->parser->getStream()->test('without')) {
         $this->parser->getStream()->next();
         $this->parser->getStream()->expect('loop');
         $withLoop = false;
     }
     $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
     $body = $this->parser->subparse(array($this, 'decideForFork'));
     if ($this->parser->getStream()->next()->getValue() == 'else') {
         $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
         $else = $this->parser->subparse(array($this, 'decideForEnd'), true);
     } else {
         $else = null;
     }
     $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
     if (count($targets) > 1) {
         $keyTarget = $targets->getNode(0);
         $valueTarget = $targets->getNode(1);
     } else {
         $keyTarget = new Twig_Node_Expression_AssignName('_key', $lineno);
         $valueTarget = $targets->getNode(0);
     }
     return new Twig_Node_For($keyTarget, $valueTarget, $seq, $body, $else, $withLoop, $lineno, $this->getTag());
 }
开发者ID:vjousse,项目名称:devorigin-symfony2,代码行数:37,代码来源:For.php

示例5: parse

 /**
  * Parses {% requireEdition %} tags.
  *
  * @param \Twig_Token $token
  *
  * @return RequireEdition_Node
  */
 public function parse(\Twig_Token $token)
 {
     $lineno = $token->getLine();
     $editionName = $this->parser->getExpressionParser()->parseExpression();
     $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
     return new RequireEdition_Node(array('editionName' => $editionName), array(), $lineno, $this->getTag());
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:14,代码来源:RequireEdition_TokenParser.php

示例6: parse

 /**
  * {@inheritdoc}
  */
 public function parse(\Twig_Token $token)
 {
     $lineno = $token->getLine();
     $stream = $this->parser->getStream();
     $variable = $this->parser->getExpressionParser()->parseAssignmentExpression();
     $stream->expect(\Twig_Token::NAME_TYPE, 'from');
     $collectionType = $this->parser->getExpressionParser()->parseAssignmentExpression();
     $collectionFilters = null;
     if ($stream->test(\Twig_Token::PUNCTUATION_TYPE, '|')) {
         $collectionFilters = $this->parser->getExpressionParser()->parsePostfixExpression($collectionType);
     }
     $parameters = null;
     if ($stream->nextIf(\Twig_Token::NAME_TYPE, 'with')) {
         $parameters = $this->parser->getExpressionParser()->parseExpression();
     }
     $ifExpression = null;
     if ($stream->nextIf(\Twig_Token::NAME_TYPE, 'if')) {
         $ifExpression = $this->parser->getExpressionParser()->parseExpression();
     }
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     $body = $this->parser->subparse([$this, 'decideGimmeListFork']);
     if ($stream->next()->getValue() == 'else') {
         $stream->expect(\Twig_Token::BLOCK_END_TYPE);
         $else = $this->parser->subparse([$this, 'decideGimmeListEnd'], true);
     } else {
         $else = null;
     }
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     return new GimmeListNode($variable, $collectionType, $collectionFilters, $parameters, $ifExpression, $else, $body, $lineno, $this->getTag());
 }
开发者ID:superdesk,项目名称:web-publisher,代码行数:33,代码来源:GimmeListTokenParser.php

示例7: parse

 /**
  * Parses {% redirect %} tags.
  *
  * @param \Twig_Token $token
  *
  * @return Redirect_Node
  */
 public function parse(\Twig_Token $token)
 {
     $lineno = $token->getLine();
     $path = $this->parser->getExpressionParser()->parseExpression();
     $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
     return new Redirect_Node(array('path' => $path), array(), $lineno, $this->getTag());
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:14,代码来源:Redirect_TokenParser.php

示例8: parse

 /**
  * {@inheritDoc}
  */
 public function parse(\Twig_Token $token)
 {
     $stream = $this->parser->getStream();
     $expressionParser = $this->parser->getExpressionParser();
     if ($stream->test(\Twig_Token::NAME_TYPE)) {
         $currentToken = $stream->getCurrent();
         $currentValue = $currentToken->getValue();
         $currentLine = $currentToken->getLine();
         // Creates expression: placeholder_name|default('placeholder_name')
         // To parse either variable value or name
         $name = new \Twig_Node_Expression_Filter_Default(new \Twig_Node_Expression_Name($currentValue, $currentLine), new \Twig_Node_Expression_Constant('default', $currentLine), new \Twig_Node(array(new \Twig_Node_Expression_Constant($currentValue, $currentLine)), array(), $currentLine), $currentLine);
         $stream->next();
     } else {
         $name = $expressionParser->parseExpression();
     }
     if ($stream->nextIf(\Twig_Token::NAME_TYPE, 'with')) {
         $variables = $expressionParser->parseExpression();
     } else {
         $variables = new \Twig_Node_Expression_Constant(array(), $token->getLine());
     }
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     // build expression to call 'placeholder' function
     $expr = new \Twig_Node_Expression_Function('placeholder', new \Twig_Node(array('name' => $name, 'variables' => $variables)), $token->getLine());
     return new \Twig_Node_Print($expr, $token->getLine(), $this->getTag());
 }
开发者ID:Maksold,项目名称:platform,代码行数:28,代码来源:PlaceholderTokenParser.php

示例9: parse

 public function parse(\Twig_Token $token)
 {
     $lineno = $token->getLine();
     $type = $this->parser->getStream()->expect(\Twig_Token::NAME_TYPE)->getValue();
     $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
     return new OutputNode($type, $lineno, $this->getTag());
 }
开发者ID:wave-framework,项目名称:wave,代码行数:7,代码来源:Output.php

示例10: parse

 /**
  * Parses a token and returns a node.
  *
  * @param Twig_Token $token A Twig_Token instance
  *
  * @return Twig_NodeInterface A Twig_NodeInterface instance
  */
 public function parse(Twig_Token $token)
 {
     $lineno = $token->getLine();
     $name = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue();
     $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
     return new Twig_Node_BlockReference($name, $lineno, $this->getTag());
 }
开发者ID:kuzmichus,项目名称:schoolreg,代码行数:14,代码来源:Display.php

示例11: parse

 /**
  * Parses {% requireLogin %} tags.
  *
  * @param \Twig_Token $token
  *
  * @return RequireLogin_Node
  */
 public function parse(\Twig_Token $token)
 {
     $lineno = $token->getLine();
     $header = $this->parser->getExpressionParser()->parseExpression();
     $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
     return new Header_Node(array('header' => $header), array(), $lineno, $this->getTag());
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:14,代码来源:Header_TokenParser.php

示例12: parse

 public function parse(\Twig_Token $token)
 {
     $lineno = $token->getLine();
     $stream = $this->parser->getStream();
     // 'svg'
     $name = $stream->expect(\Twig_Token::STRING_TYPE)->getValue();
     // %} (from {% stamp %})
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     $aboveDumps = [];
     while (true) {
         // everything above {% stamp_dump %}
         $aboveDumps[] = $this->parser->subparse(function (\Twig_Token $token) {
             return $token->test('stamp_dump');
         });
         // allow nested {% stamp %} usage using distinct names
         $dumpName = $stream->next() && $stream->expect(\Twig_Token::STRING_TYPE)->getValue();
         if ($dumpName == $name) {
             break;
         }
     }
     // %} (from {% stamp_dump %})
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     // everything below {% stamp_dump %}
     $belowDump = $this->parser->subparse(function (\Twig_Token $token) {
         return $token->test('endstamp');
     });
     // %} (from {% endstamp %})
     $stream->next() && $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     return new StampNode($name, $aboveDumps, $belowDump, $lineno, $this->getTag());
 }
开发者ID:blablacar,项目名称:twig-stamp,代码行数:30,代码来源:StampTokenParser.php

示例13: parse

 /**
  * Parses a token and returns a node.
  *
  * @param Twig_Token $token A Twig_Token instance
  *
  * @return Twig_NodeInterface A Twig_NodeInterface instance
  */
 public function parse(Twig_Token $token)
 {
     $stream = $this->parser->getStream();
     $collection = $this->parser->getExpressionParser()->parseExpression();
     $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
     return new TwigAssets_Node_UseAsset($collection, $token->getLine(), $this->getTag());
 }
开发者ID:Webapper,项目名称:TwigAssets,代码行数:14,代码来源:UseAsset.php

示例14: parse

 public function parse(Twig_Token $token)
 {
     $lineno = $token->getLine();
     $expr = $this->parser->getExpressionParser()->parseExpression();
     $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
     $body = $this->parser->subparse(array($this, 'decideIfFork'));
     $tests = array(array($expr, $body));
     $else = null;
     $end = false;
     while (!$end) {
         try {
             switch ($this->parser->getStream()->next()->getValue()) {
                 case 'else':
                     $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
                     $else = $this->parser->subparse(array($this, 'decideIfEnd'));
                     break;
                 case 'elseif':
                     $expr = $this->parser->getExpressionParser()->parseExpression();
                     $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
                     $body = $this->parser->subparse(array($this, 'decideIfFork'));
                     $tests[] = array($expr, $body);
                     break;
                 case 'endif':
                     $end = true;
                     break;
                 default:
                     throw new Twig_SyntaxError('', -1);
             }
         } catch (Twig_SyntaxError $e) {
             throw new Twig_SyntaxError(sprintf('Unexpected end of template. Twig was looking for the following tags "else", "elseif", or "endif" to close the "if" block started at line %d)', $lineno), -1);
         }
     }
     $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
     return new Twig_Node_If($tests, $else, $lineno, $this->getTag());
 }
开发者ID:jstanden,项目名称:devblocks,代码行数:35,代码来源:If.php

示例15: parse

 /**
  * Parses a token and returns a node.
  *
  * @param Twig_Token $token A Twig_Token instance
  *
  * @return Twig_NodeInterface A Twig_NodeInterface instance
  */
 public function parse(Twig_Token $token)
 {
     $parser = $this->parser;
     $stream = $parser->getStream();
     $default = null;
     $cases = array();
     $end = false;
     $name = $parser->getExpressionParser()->parseExpression();
     $stream->expect(Twig_Token::BLOCK_END_TYPE);
     $stream->expect(Twig_Token::TEXT_TYPE);
     $stream->expect(Twig_Token::BLOCK_START_TYPE);
     while (!$end) {
         $v = $stream->next();
         switch ($v->getValue()) {
             case 'default':
                 $stream->expect(Twig_Token::BLOCK_END_TYPE);
                 $default = $parser->subparse(array($this, 'decideIfEnd'));
                 break;
             case 'case':
                 $expr = $parser->getExpressionParser()->parseExpression();
                 $stream->expect(Twig_Token::BLOCK_END_TYPE);
                 $body = $parser->subparse(array($this, 'decideIfFork'));
                 $cases[] = $expr;
                 $cases[] = $body;
                 break;
             case 'endswitch':
                 $end = true;
                 break;
             default:
                 throw new Twig_Error_Syntax(sprintf('Unexpected end of template. Twig was looking for the following tags "case", "default", or "endswitch" to close the "switch" block started at line %d)', $lineno), -1);
         }
     }
     $stream->expect(Twig_Token::BLOCK_END_TYPE);
     return new Twig_Node_Switch($name, new Twig_Node($cases), $default, $token->getLine(), $this->getTag());
 }
开发者ID:josephzhao,项目名称:map2ucore,代码行数:42,代码来源:Switch_TokenParser.php


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