[ Index ]

PHP Cross Reference of phpBB-3.3.12-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\AbstractTokenParser
  18  {
  19      /**
  20      * Parses a token and returns a node.
  21      *
  22      * @param \Twig\Token $token A Twig\Token instance
  23      *
  24      * @return \Twig\Node\Node A Twig\Node instance
  25      * @throws \Twig\Error\SyntaxError
  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\NameExpression)
  41              {
  42                  // This would happen if someone improperly formed their DEFINE syntax
  43                  // e.g. <!-- DEFINE $VAR = foo -->
  44                  throw new \Twig\Error\SyntaxError('Invalid DEFINE', $token->getLine(), $this->parser->getStream()->getSourceContext()->getPath());
  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: Sun Jun 23 12:25:44 2024 Cross-referenced by PHPXref 0.7.1