Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

If.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 2.65 KiB


 01  <?php
 02   
 03  /*
 04   * This file is part of Twig.
 05   *
 06   * (c) 2009 Fabien Potencier
 07   * (c) 2009 Armin Ronacher
 08   *
 09   * For the full copyright and license information, please view the LICENSE
 10   * file that was distributed with this source code.
 11   */
 12   
 13  /**
 14   * Tests a condition.
 15   *
 16   * <pre>
 17   * {% if users %}
 18   *  <ul>
 19   *    {% for user in users %}
 20   *      <li>{{ user.username|e }}</li>
 21   *    {% endfor %}
 22   *  </ul>
 23   * {% endif %}
 24   * </pre>
 25   */
 26  class Twig_TokenParser_If extends Twig_TokenParser
 27  {
 28      /**
 29       * Parses a token and returns a node.
 30       *
 31       * @param Twig_Token $token A Twig_Token instance
 32       *
 33       * @return Twig_NodeInterface A Twig_NodeInterface instance
 34       */
 35      public function parse(Twig_Token $token)
 36      {
 37          $lineno = $token->getLine();
 38          $expr = $this->parser->getExpressionParser()->parseExpression();
 39          $stream = $this->parser->getStream();
 40          $stream->expect(Twig_Token::BLOCK_END_TYPE);
 41          $body = $this->parser->subparse(array($this, 'decideIfFork'));
 42          $tests = array($expr, $body);
 43          $else = null;
 44   
 45          $end = false;
 46          while (!$end) {
 47              switch ($stream->next()->getValue()) {
 48                  case 'else':
 49                      $stream->expect(Twig_Token::BLOCK_END_TYPE);
 50                      $else = $this->parser->subparse(array($this, 'decideIfEnd'));
 51                      break;
 52   
 53                  case 'elseif':
 54                      $expr = $this->parser->getExpressionParser()->parseExpression();
 55                      $stream->expect(Twig_Token::BLOCK_END_TYPE);
 56                      $body = $this->parser->subparse(array($this, 'decideIfFork'));
 57                      $tests[] = $expr;
 58                      $tests[] = $body;
 59                      break;
 60   
 61                  case 'endif':
 62                      $end = true;
 63                      break;
 64   
 65                  default:
 66                      throw new Twig_Error_Syntax(sprintf('Unexpected end of template. Twig was looking for the following tags "else", "elseif", or "endif" to close the "if" block started at line %d)', $lineno), $stream->getCurrent()->getLine(), $stream->getFilename());
 67              }
 68          }
 69   
 70          $stream->expect(Twig_Token::BLOCK_END_TYPE);
 71   
 72          return new Twig_Node_If(new Twig_Node($tests), $else, $lineno, $this->getTag());
 73      }
 74   
 75      public function decideIfFork(Twig_Token $token)
 76      {
 77          return $token->test(array('elseif', 'else', 'endif'));
 78      }
 79   
 80      public function decideIfEnd(Twig_Token $token)
 81      {
 82          return $token->test(array('endif'));
 83      }
 84   
 85      /**
 86       * Gets the tag name associated with this token parser.
 87       *
 88       * @return string The tag name
 89       */
 90      public function getTag()
 91      {
 92          return 'if';
 93      }
 94  }
 95