[ Index ]

PHP Cross Reference of phpBB-3.3.12-deutsch

title

Body

[close]

/vendor/twig/twig/src/TokenParser/ -> UseTokenParser.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of Twig.
   5   *
   6   * (c) Fabien Potencier
   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 Twig\TokenParser;
  13  
  14  use Twig\Error\SyntaxError;
  15  use Twig\Node\Expression\ConstantExpression;
  16  use Twig\Node\Node;
  17  use Twig\Token;
  18  
  19  /**
  20   * Imports blocks defined in another template into the current template.
  21   *
  22   *    {% extends "base.html" %}
  23   *
  24   *    {% use "blocks.html" %}
  25   *
  26   *    {% block title %}{% endblock %}
  27   *    {% block content %}{% endblock %}
  28   *
  29   * @see https://twig.symfony.com/doc/templates.html#horizontal-reuse for details.
  30   */
  31  final class UseTokenParser extends AbstractTokenParser
  32  {
  33      public function parse(Token $token)
  34      {
  35          $template = $this->parser->getExpressionParser()->parseExpression();
  36          $stream = $this->parser->getStream();
  37  
  38          if (!$template instanceof ConstantExpression) {
  39              throw new SyntaxError('The template references in a "use" statement must be a string.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
  40          }
  41  
  42          $targets = [];
  43          if ($stream->nextIf('with')) {
  44              do {
  45                  $name = $stream->expect(/* Token::NAME_TYPE */ 5)->getValue();
  46  
  47                  $alias = $name;
  48                  if ($stream->nextIf('as')) {
  49                      $alias = $stream->expect(/* Token::NAME_TYPE */ 5)->getValue();
  50                  }
  51  
  52                  $targets[$name] = new ConstantExpression($alias, -1);
  53  
  54                  if (!$stream->nextIf(/* Token::PUNCTUATION_TYPE */ 9, ',')) {
  55                      break;
  56                  }
  57              } while (true);
  58          }
  59  
  60          $stream->expect(/* Token::BLOCK_END_TYPE */ 3);
  61  
  62          $this->parser->addTrait(new Node(['template' => $template, 'targets' => new Node($targets)]));
  63  
  64          return new Node();
  65      }
  66  
  67      public function getTag()
  68      {
  69          return 'use';
  70      }
  71  }
  72  
  73  class_alias('Twig\TokenParser\UseTokenParser', 'Twig_TokenParser_Use');


Generated: Sun Jun 23 12:25:44 2024 Cross-referenced by PHPXref 0.7.1