Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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

TokenStream.php

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 3.86 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 stream.
015   *
016   * @author Fabien Potencier <fabien@symfony.com>
017   */
018  class Twig_TokenStream
019  {
020      protected $tokens;
021      protected $current = 0;
022      protected $filename;
023   
024      /**
025       * Constructor.
026       *
027       * @param array  $tokens   An array of tokens
028       * @param string $filename The name of the filename which tokens are associated with
029       */
030      public function __construct(array $tokens, $filename = null)
031      {
032          $this->tokens = $tokens;
033          $this->filename = $filename;
034      }
035   
036      /**
037       * Returns a string representation of the token stream.
038       *
039       * @return string
040       */
041      public function __toString()
042      {
043          return implode("\n", $this->tokens);
044      }
045   
046      public function injectTokens(array $tokens)
047      {
048          $this->tokens = array_merge(array_slice($this->tokens, 0, $this->current), $tokens, array_slice($this->tokens, $this->current));
049      }
050   
051      /**
052       * Sets the pointer to the next token and returns the old one.
053       *
054       * @return Twig_Token
055       */
056      public function next()
057      {
058          if (!isset($this->tokens[++$this->current])) {
059              throw new Twig_Error_Syntax('Unexpected end of template.', $this->tokens[$this->current - 1]->getLine(), $this->filename);
060          }
061   
062          return $this->tokens[$this->current - 1];
063      }
064   
065      /**
066       * Tests a token, sets the pointer to the next one and returns it or throws a syntax error.
067       *
068       * @return Twig_Token|null The next token if the condition is true, null otherwise
069       */
070      public function nextIf($primary, $secondary = null)
071      {
072          if ($this->tokens[$this->current]->test($primary, $secondary)) {
073              return $this->next();
074          }
075      }
076   
077      /**
078       * Tests a token and returns it or throws a syntax error.
079       *
080       * @return Twig_Token
081       */
082      public function expect($type, $value = null, $message = null)
083      {
084          $token = $this->tokens[$this->current];
085          if (!$token->test($type, $value)) {
086              $line = $token->getLine();
087              throw new Twig_Error_Syntax(sprintf('%sUnexpected token "%s" of value "%s" ("%s" expected%s).',
088                  $message ? $message.'. ' : '',
089                  Twig_Token::typeToEnglish($token->getType()), $token->getValue(),
090                  Twig_Token::typeToEnglish($type), $value ? sprintf(' with value "%s"', $value) : ''),
091                  $line,
092                  $this->filename
093              );
094          }
095          $this->next();
096   
097          return $token;
098      }
099   
100      /**
101       * Looks at the next token.
102       *
103       * @param int $number
104       *
105       * @return Twig_Token
106       */
107      public function look($number = 1)
108      {
109          if (!isset($this->tokens[$this->current + $number])) {
110              throw new Twig_Error_Syntax('Unexpected end of template.', $this->tokens[$this->current + $number - 1]->getLine(), $this->filename);
111          }
112   
113          return $this->tokens[$this->current + $number];
114      }
115   
116      /**
117       * Tests the current token.
118       *
119       * @return bool
120       */
121      public function test($primary, $secondary = null)
122      {
123          return $this->tokens[$this->current]->test($primary, $secondary);
124      }
125   
126      /**
127       * Checks if end of stream was reached.
128       *
129       * @return bool
130       */
131      public function isEOF()
132      {
133          return $this->tokens[$this->current]->getType() === Twig_Token::EOF_TYPE;
134      }
135   
136      /**
137       * Gets the current token.
138       *
139       * @return Twig_Token
140       */
141      public function getCurrent()
142      {
143          return $this->tokens[$this->current];
144      }
145   
146      /**
147       * Gets the filename associated with this stream.
148       *
149       * @return string
150       */
151      public function getFilename()
152      {
153          return $this->filename;
154      }
155  }
156