[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/symfony/twig-bridge/TokenParser/ -> TransChoiceTokenParser.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the Symfony package.
   5   *
   6   * (c) Fabien Potencier <fabien@symfony.com>
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  namespace Symfony\Bridge\Twig\TokenParser;
  13  
  14  use Symfony\Bridge\Twig\Node\TransNode;
  15  use Twig\Error\SyntaxError;
  16  use Twig\Node\Expression\AbstractExpression;
  17  use Twig\Node\Expression\ArrayExpression;
  18  use Twig\Node\Node;
  19  use Twig\Node\TextNode;
  20  use Twig\Token;
  21  
  22  /**
  23   * Token Parser for the 'transchoice' tag.
  24   *
  25   * @author Fabien Potencier <fabien@symfony.com>
  26   */
  27  class TransChoiceTokenParser extends TransTokenParser
  28  {
  29      /**
  30       * Parses a token and returns a node.
  31       *
  32       * @return Node
  33       *
  34       * @throws SyntaxError
  35       */
  36      public function parse(Token $token)
  37      {
  38          $lineno = $token->getLine();
  39          $stream = $this->parser->getStream();
  40  
  41          $vars = new ArrayExpression(array(), $lineno);
  42  
  43          $count = $this->parser->getExpressionParser()->parseExpression();
  44  
  45          $domain = null;
  46          $locale = null;
  47  
  48          if ($stream->test('with')) {
  49              // {% transchoice count with vars %}
  50              $stream->next();
  51              $vars = $this->parser->getExpressionParser()->parseExpression();
  52          }
  53  
  54          if ($stream->test('from')) {
  55              // {% transchoice count from "messages" %}
  56              $stream->next();
  57              $domain = $this->parser->getExpressionParser()->parseExpression();
  58          }
  59  
  60          if ($stream->test('into')) {
  61              // {% transchoice count into "fr" %}
  62              $stream->next();
  63              $locale = $this->parser->getExpressionParser()->parseExpression();
  64          }
  65  
  66          $stream->expect(Token::BLOCK_END_TYPE);
  67  
  68          $body = $this->parser->subparse(array($this, 'decideTransChoiceFork'), true);
  69  
  70          if (!$body instanceof TextNode && !$body instanceof AbstractExpression) {
  71              throw new SyntaxError('A message inside a transchoice tag must be a simple text.', $body->getTemplateLine(), $stream->getSourceContext()->getName());
  72          }
  73  
  74          $stream->expect(Token::BLOCK_END_TYPE);
  75  
  76          return new TransNode($body, $domain, $count, $vars, $locale, $lineno, $this->getTag());
  77      }
  78  
  79      public function decideTransChoiceFork($token)
  80      {
  81          return $token->test(array('endtranschoice'));
  82      }
  83  
  84      /**
  85       * Gets the tag name associated with this token parser.
  86       *
  87       * @return string The tag name
  88       */
  89      public function getTag()
  90      {
  91          return 'transchoice';
  92      }
  93  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1