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

SwitchStatement.php

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


 01  <?php
 02   
 03  /**
 04  * @package   s9e\TextFormatter
 05  * @copyright Copyright (c) 2010-2022 The s9e authors
 06  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
 07  */
 08  namespace s9e\TextFormatter\Configurator\RendererGenerators\PHP;
 09   
 10  class SwitchStatement
 11  {
 12      /**
 13      * @var array Dictionary of [value => php code]
 14      */
 15      protected $branchesCode;
 16   
 17      /**
 18      * @var string PHP code for the default case
 19      */
 20      protected $defaultCode;
 21   
 22      /**
 23      * @param array  $branchesCode Dictionary of [value => php code]
 24      * @param string $defaultCode  PHP code for the default case
 25      */
 26      public function __construct(array $branchesCode, $defaultCode = '')
 27      {
 28          ksort($branchesCode);
 29   
 30          $this->branchesCode = $branchesCode;
 31          $this->defaultCode  = $defaultCode;
 32      }
 33   
 34      /**
 35      * Create and return the source code for a switch statement
 36      *
 37      * @param  string $expr         Expression used for the switch clause
 38      * @param  array  $branchesCode Dictionary of [value => php code]
 39      * @param  string $defaultCode  PHP code for the default case
 40      * @return string               PHP code
 41      */
 42      public static function generate($expr, array $branchesCode, $defaultCode = '')
 43      {
 44          $switch = new static($branchesCode, $defaultCode);
 45   
 46          return $switch->getSource($expr);
 47      }
 48   
 49      /**
 50      * Return the source code for this switch statement
 51      *
 52      * @param  string $expr Expression used for the switch clause
 53      * @return string       PHP code
 54      */
 55      protected function getSource($expr)
 56      {
 57          $php = 'switch(' . $expr . '){';
 58          foreach ($this->getValuesPerCodeBranch() as $branchCode => $values)
 59          {
 60              foreach ($values as $value)
 61              {
 62                  $php .= 'case' . var_export((string) $value, true) . ':';
 63              }
 64              $php .= $branchCode . 'break;';
 65          }
 66          if ($this->defaultCode > '')
 67          {
 68              $php .= 'default:' . $this->defaultCode;
 69          }
 70          $php = preg_replace('(break;$)', '', $php) . '}';
 71   
 72          return $php;
 73      }
 74   
 75      /**
 76      * Group branches by their content and return the switch values for each branch
 77      *
 78      * @return array
 79      */
 80      protected function getValuesPerCodeBranch()
 81      {
 82          $values = [];
 83          foreach ($this->branchesCode as $value => $branchCode)
 84          {
 85              $values[$branchCode][] = $value;
 86          }
 87   
 88          return $values;
 89      }
 90  }