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

Token.php

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 6.19 KiB


 001  <?php
 002   
 003  /*
 004   * This file is part of Twig.
 005   *
 006   * (c) 2009 Fabien Potencier
 007   * (c) 2009 Armin Ronacher
 008   *
 009   * For the full copyright and license information, please view the LICENSE
 010   * file that was distributed with this source code.
 011   */
 012   
 013  /**
 014   * Represents a Token.
 015   *
 016   * @author Fabien Potencier <fabien@symfony.com>
 017   */
 018  class Twig_Token
 019  {
 020      protected $value;
 021      protected $type;
 022      protected $lineno;
 023   
 024      const EOF_TYPE                  = -1;
 025      const TEXT_TYPE                 = 0;
 026      const BLOCK_START_TYPE          = 1;
 027      const VAR_START_TYPE            = 2;
 028      const BLOCK_END_TYPE            = 3;
 029      const VAR_END_TYPE              = 4;
 030      const NAME_TYPE                 = 5;
 031      const NUMBER_TYPE               = 6;
 032      const STRING_TYPE               = 7;
 033      const OPERATOR_TYPE             = 8;
 034      const PUNCTUATION_TYPE          = 9;
 035      const INTERPOLATION_START_TYPE  = 10;
 036      const INTERPOLATION_END_TYPE    = 11;
 037   
 038      /**
 039       * Constructor.
 040       *
 041       * @param integer $type   The type of the token
 042       * @param string  $value  The token value
 043       * @param integer $lineno The line position in the source
 044       */
 045      public function __construct($type, $value, $lineno)
 046      {
 047          $this->type   = $type;
 048          $this->value  = $value;
 049          $this->lineno = $lineno;
 050      }
 051   
 052      /**
 053       * Returns a string representation of the token.
 054       *
 055       * @return string A string representation of the token
 056       */
 057      public function __toString()
 058      {
 059          return sprintf('%s(%s)', self::typeToString($this->type, true, $this->lineno), $this->value);
 060      }
 061   
 062      /**
 063       * Tests the current token for a type and/or a value.
 064       *
 065       * Parameters may be:
 066       * * just type
 067       * * type and value (or array of possible values)
 068       * * just value (or array of possible values) (NAME_TYPE is used as type)
 069       *
 070       * @param array|integer     $type   The type to test
 071       * @param array|string|null $values The token value
 072       *
 073       * @return Boolean
 074       */
 075      public function test($type, $values = null)
 076      {
 077          if (null === $values && !is_int($type)) {
 078              $values = $type;
 079              $type = self::NAME_TYPE;
 080          }
 081   
 082          return ($this->type === $type) && (
 083              null === $values ||
 084              (is_array($values) && in_array($this->value, $values)) ||
 085              $this->value == $values
 086          );
 087      }
 088   
 089      /**
 090       * Gets the line.
 091       *
 092       * @return integer The source line
 093       */
 094      public function getLine()
 095      {
 096          return $this->lineno;
 097      }
 098   
 099      /**
 100       * Gets the token type.
 101       *
 102       * @return integer The token type
 103       */
 104      public function getType()
 105      {
 106          return $this->type;
 107      }
 108   
 109      /**
 110       * Gets the token value.
 111       *
 112       * @return string The token value
 113       */
 114      public function getValue()
 115      {
 116          return $this->value;
 117      }
 118   
 119      /**
 120       * Returns the constant representation (internal) of a given type.
 121       *
 122       * @param integer $type  The type as an integer
 123       * @param Boolean $short Whether to return a short representation or not
 124       * @param integer $line  The code line
 125       *
 126       * @return string The string representation
 127       */
 128      public static function typeToString($type, $short = false, $line = -1)
 129      {
 130          switch ($type) {
 131              case self::EOF_TYPE:
 132                  $name = 'EOF_TYPE';
 133                  break;
 134              case self::TEXT_TYPE:
 135                  $name = 'TEXT_TYPE';
 136                  break;
 137              case self::BLOCK_START_TYPE:
 138                  $name = 'BLOCK_START_TYPE';
 139                  break;
 140              case self::VAR_START_TYPE:
 141                  $name = 'VAR_START_TYPE';
 142                  break;
 143              case self::BLOCK_END_TYPE:
 144                  $name = 'BLOCK_END_TYPE';
 145                  break;
 146              case self::VAR_END_TYPE:
 147                  $name = 'VAR_END_TYPE';
 148                  break;
 149              case self::NAME_TYPE:
 150                  $name = 'NAME_TYPE';
 151                  break;
 152              case self::NUMBER_TYPE:
 153                  $name = 'NUMBER_TYPE';
 154                  break;
 155              case self::STRING_TYPE:
 156                  $name = 'STRING_TYPE';
 157                  break;
 158              case self::OPERATOR_TYPE:
 159                  $name = 'OPERATOR_TYPE';
 160                  break;
 161              case self::PUNCTUATION_TYPE:
 162                  $name = 'PUNCTUATION_TYPE';
 163                  break;
 164              case self::INTERPOLATION_START_TYPE:
 165                  $name = 'INTERPOLATION_START_TYPE';
 166                  break;
 167              case self::INTERPOLATION_END_TYPE:
 168                  $name = 'INTERPOLATION_END_TYPE';
 169                  break;
 170              default:
 171                  throw new LogicException(sprintf('Token of type "%s" does not exist.', $type));
 172          }
 173   
 174          return $short ? $name : 'Twig_Token::'.$name;
 175      }
 176   
 177      /**
 178       * Returns the english representation of a given type.
 179       *
 180       * @param integer $type The type as an integer
 181       * @param integer $line The code line
 182       *
 183       * @return string The string representation
 184       */
 185      public static function typeToEnglish($type, $line = -1)
 186      {
 187          switch ($type) {
 188              case self::EOF_TYPE:
 189                  return 'end of template';
 190              case self::TEXT_TYPE:
 191                  return 'text';
 192              case self::BLOCK_START_TYPE:
 193                  return 'begin of statement block';
 194              case self::VAR_START_TYPE:
 195                  return 'begin of print statement';
 196              case self::BLOCK_END_TYPE:
 197                  return 'end of statement block';
 198              case self::VAR_END_TYPE:
 199                  return 'end of print statement';
 200              case self::NAME_TYPE:
 201                  return 'name';
 202              case self::NUMBER_TYPE:
 203                  return 'number';
 204              case self::STRING_TYPE:
 205                  return 'string';
 206              case self::OPERATOR_TYPE:
 207                  return 'operator';
 208              case self::PUNCTUATION_TYPE:
 209                  return 'punctuation';
 210              case self::INTERPOLATION_START_TYPE:
 211                  return 'begin of string interpolation';
 212              case self::INTERPOLATION_END_TYPE:
 213                  return 'end of string interpolation';
 214              default:
 215                  throw new LogicException(sprintf('Token of type "%s" does not exist.', $type));
 216          }
 217      }
 218  }
 219