當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。