[ Index ]

PHP Cross Reference of phpBB-3.2.8-deutsch

title

Body

[close]

/phpbb/template/twig/tokenparser/ -> defineparser.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @copyright Portions (c) 2009 Fabien Potencier, Armin Ronacher
   8  * @license GNU General Public License, version 2 (GPL-2.0)
   9  *
  10  * For full copyright and license information, please see
  11  * the docs/CREDITS.txt file.
  12  *
  13  */
  14  
  15  namespace phpbb\template\twig\tokenparser;
  16  
  17  class defineparser extends \Twig_TokenParser
  18  {
  19      /**
  20      * Parses a token and returns a node.
  21      *
  22      * @param \Twig_Token $token A Twig_Token instance
  23      *
  24      * @return \Twig_NodeInterface A Twig_NodeInterface instance
  25      * @throws \Twig_Error_Syntax
  26      * @throws \phpbb\template\twig\node\definenode
  27      */
  28  	public function parse(\Twig_Token $token)
  29      {
  30          $lineno = $token->getLine();
  31          $stream = $this->parser->getStream();
  32          $name = $this->parser->getExpressionParser()->parseExpression();
  33  
  34          $capture = false;
  35          if ($stream->test(\Twig_Token::OPERATOR_TYPE, '='))
  36          {
  37              $stream->next();
  38              $value = $this->parser->getExpressionParser()->parseExpression();
  39  
  40              if ($value instanceof \Twig_Node_Expression_Name)
  41              {
  42                  // This would happen if someone improperly formed their DEFINE syntax
  43                  // e.g. <!-- DEFINE $VAR = foo -->
  44                  throw new \Twig_Error_Syntax('Invalid DEFINE', $token->getLine(), $this->parser->getFilename());
  45              }
  46  
  47              $stream->expect(\Twig_Token::BLOCK_END_TYPE);
  48          }
  49          else
  50          {
  51              $capture = true;
  52  
  53              $stream->expect(\Twig_Token::BLOCK_END_TYPE);
  54  
  55              $value = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
  56              $stream->expect(\Twig_Token::BLOCK_END_TYPE);
  57          }
  58  
  59          return new \phpbb\template\twig\node\definenode($capture, $name, $value, $lineno, $this->getTag());
  60      }
  61  
  62  	public function decideBlockEnd(\Twig_Token $token)
  63      {
  64          return $token->test('ENDDEFINE');
  65      }
  66  
  67      /**
  68      * Gets the tag name associated with this token parser.
  69      *
  70      * @return string The tag name
  71      */
  72  	public function getTag()
  73      {
  74          return 'DEFINE';
  75      }
  76  }


Generated: Tue Apr 7 19:42:26 2020 Cross-referenced by PHPXref 0.7.1