Verzeichnisstruktur phpBB-3.3.16


Veröffentlicht
27.04.2026

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

AbstractOptimizer.php

Zuletzt modifiziert: 01.05.2026, 11:28 - Dateigröße: 2.72 KiB


 001  <?php
 002   
 003  /**
 004  * @package   s9e\TextFormatter
 005  * @copyright Copyright (c) 2010-2022 The s9e authors
 006  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
 007  */
 008  namespace s9e\TextFormatter\Configurator\RendererGenerators\PHP;
 009   
 010  abstract class AbstractOptimizer
 011  {
 012      /**
 013      * @var integer Number of tokens
 014      */
 015      protected $cnt;
 016   
 017      /**
 018      * @var integer Current token index
 019      */
 020      protected $i;
 021   
 022      /**
 023      * @var boolean Whether the tokens have been changed
 024      */
 025      protected $changed;
 026   
 027      /**
 028      * @var array Tokens from current source
 029      */
 030      protected $tokens;
 031   
 032      /**
 033      * Optimize the control structures of a script
 034      *
 035      * Removes brackets in control structures wherever possible. Prevents the generation of EXT_STMT
 036      * opcodes where they're not strictly required.
 037      *
 038      * @param  string $php Original code
 039      * @return string      Optimized code
 040      */
 041      public function optimize($php)
 042      {
 043          $this->reset($php);
 044          $this->optimizeTokens();
 045   
 046          // Rebuild the source if it has changed
 047          if ($this->changed)
 048          {
 049              $php = $this->serialize();
 050          }
 051   
 052          // Free the memory taken up by the tokens
 053          unset($this->tokens);
 054   
 055          return $php;
 056      }
 057   
 058      /**
 059      * Optimize the stored tokens
 060      *
 061      * @return void
 062      */
 063      abstract protected function optimizeTokens();
 064   
 065      /**
 066      * Reset the internal state of this optimizer
 067      *
 068      * @param  string $php PHP source
 069      * @return void
 070      */
 071      protected function reset($php)
 072      {
 073          $this->tokens  = token_get_all('<?php ' . $php);
 074          $this->i       = 0;
 075          $this->cnt     = count($this->tokens);
 076          $this->changed = false;
 077      }
 078   
 079      /**
 080      * Serialize the tokens back to source
 081      *
 082      * @return string
 083      */
 084      protected function serialize()
 085      {
 086          // Remove the first token, which should be T_OPEN_TAG, aka "<?php"
 087          unset($this->tokens[0]);
 088   
 089          $php = '';
 090          foreach ($this->tokens as $token)
 091          {
 092              $php .= (is_string($token)) ? $token : $token[1];
 093          }
 094   
 095          return $php;
 096      }
 097   
 098      /**
 099      * Move the internal cursor until it reaches given string
 100      *
 101      * @param  string $str String to reach
 102      * @return void
 103      */
 104      protected function skipToString($str)
 105      {
 106          while (++$this->i < $this->cnt && $this->tokens[$this->i] !== $str);
 107      }
 108   
 109      /**
 110      * Skip all whitespace
 111      *
 112      * @return void
 113      */
 114      protected function skipWhitespace()
 115      {
 116          while (++$this->i < $this->cnt && $this->tokens[$this->i][0] === T_WHITESPACE);
 117      }
 118   
 119      /**
 120      * Remove one tab of indentation off a range of PHP tokens
 121      *
 122      * @param  integer $start  Index of the first token to unindent
 123      * @param  integer $end    Index of the last token to unindent
 124      * @return void
 125      */
 126      protected function unindentBlock($start, $end)
 127      {
 128          $this->i = $start;
 129          do
 130          {
 131              if ($this->tokens[$this->i][0] === T_WHITESPACE || $this->tokens[$this->i][0] === T_DOC_COMMENT)
 132              {
 133                  $this->tokens[$this->i][1] = preg_replace("/^\t/m", '', $this->tokens[$this->i][1]);
 134              }
 135          }
 136          while (++$this->i <= $end);
 137      }
 138  }