[ Index ]

PHP Cross Reference of phpBB-3.2.8-deutsch

title

Body

[close]

/vendor/twig/twig/src/TokenParser/ -> FromTokenParser.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\AssignNameExpression;
  16  use Twig\Node\ImportNode;
  17  use Twig\Token;
  18  
  19  /**
  20   * Imports macros.
  21   *
  22   *   {% from 'forms.html' import forms %}
  23   *
  24   * @final
  25   */
  26  class FromTokenParser extends AbstractTokenParser
  27  {
  28      public function parse(Token $token)
  29      {
  30          $macro = $this->parser->getExpressionParser()->parseExpression();
  31          $stream = $this->parser->getStream();
  32          $stream->expect(Token::NAME_TYPE, 'import');
  33  
  34          $targets = [];
  35          do {
  36              $name = $stream->expect(Token::NAME_TYPE)->getValue();
  37  
  38              $alias = $name;
  39              if ($stream->nextIf('as')) {
  40                  $alias = $stream->expect(Token::NAME_TYPE)->getValue();
  41              }
  42  
  43              $targets[$name] = $alias;
  44  
  45              if (!$stream->nextIf(Token::PUNCTUATION_TYPE, ',')) {
  46                  break;
  47              }
  48          } while (true);
  49  
  50          $stream->expect(Token::BLOCK_END_TYPE);
  51  
  52          $var = new AssignNameExpression($this->parser->getVarName(), $token->getLine());
  53          $node = new ImportNode($macro, $var, $token->getLine(), $this->getTag());
  54  
  55          foreach ($targets as $name => $alias) {
  56              if ($this->parser->isReservedMacroName($name)) {
  57                  throw new SyntaxError(sprintf('"%s" cannot be an imported macro as it is a reserved keyword.', $name), $token->getLine(), $stream->getSourceContext());
  58              }
  59  
  60              $this->parser->addImportedSymbol('function', $alias, 'get'.$name, $var);
  61          }
  62  
  63          return $node;
  64      }
  65  
  66      public function getTag()
  67      {
  68          return 'from';
  69      }
  70  }
  71  
  72  class_alias('Twig\TokenParser\FromTokenParser', 'Twig_TokenParser_From');


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