[ Index ]

PHP Cross Reference of phpBB-3.2.8-deutsch

title

Body

[close]

/vendor/symfony/twig-bridge/TokenParser/ -> StopwatchTokenParser.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\StopwatchNode;
  15  use Twig\Node\Expression\AssignNameExpression;
  16  use Twig\Token;
  17  use Twig\TokenParser\AbstractTokenParser;
  18  
  19  /**
  20   * Token Parser for the stopwatch tag.
  21   *
  22   * @author Wouter J <wouter@wouterj.nl>
  23   */
  24  class StopwatchTokenParser extends AbstractTokenParser
  25  {
  26      protected $stopwatchIsAvailable;
  27  
  28      public function __construct($stopwatchIsAvailable)
  29      {
  30          $this->stopwatchIsAvailable = $stopwatchIsAvailable;
  31      }
  32  
  33      public function parse(Token $token)
  34      {
  35          $lineno = $token->getLine();
  36          $stream = $this->parser->getStream();
  37  
  38          // {% stopwatch 'bar' %}
  39          $name = $this->parser->getExpressionParser()->parseExpression();
  40  
  41          $stream->expect(Token::BLOCK_END_TYPE);
  42  
  43          // {% endstopwatch %}
  44          $body = $this->parser->subparse(array($this, 'decideStopwatchEnd'), true);
  45          $stream->expect(Token::BLOCK_END_TYPE);
  46  
  47          if ($this->stopwatchIsAvailable) {
  48              return new StopwatchNode($name, $body, new AssignNameExpression($this->parser->getVarName(), $token->getLine()), $lineno, $this->getTag());
  49          }
  50  
  51          return $body;
  52      }
  53  
  54      public function decideStopwatchEnd(Token $token)
  55      {
  56          return $token->test('endstopwatch');
  57      }
  58  
  59      public function getTag()
  60      {
  61          return 'stopwatch';
  62      }
  63  }


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