[ Index ]

PHP Cross Reference of phpBB-3.3.12-deutsch

title

Body

[close]

/vendor/twig/twig/src/TokenParser/ -> ApplyTokenParser.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\Node\Expression\TempNameExpression;
  15  use Twig\Node\Node;
  16  use Twig\Node\PrintNode;
  17  use Twig\Node\SetNode;
  18  use Twig\Token;
  19  
  20  /**
  21   * Applies filters on a section of a template.
  22   *
  23   *   {% apply upper %}
  24   *      This text becomes uppercase
  25   *   {% endapply %}
  26   */
  27  final class ApplyTokenParser extends AbstractTokenParser
  28  {
  29      public function parse(Token $token)
  30      {
  31          $lineno = $token->getLine();
  32          $name = $this->parser->getVarName();
  33  
  34          $ref = new TempNameExpression($name, $lineno);
  35          $ref->setAttribute('always_defined', true);
  36  
  37          $filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag());
  38  
  39          $this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
  40          $body = $this->parser->subparse([$this, 'decideApplyEnd'], true);
  41          $this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
  42  
  43          return new Node([
  44              new SetNode(true, $ref, $body, $lineno, $this->getTag()),
  45              new PrintNode($filter, $lineno, $this->getTag()),
  46          ]);
  47      }
  48  
  49      public function decideApplyEnd(Token $token)
  50      {
  51          return $token->test('endapply');
  52      }
  53  
  54      public function getTag()
  55      {
  56          return 'apply';
  57      }
  58  }


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