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

OptimizeChooseDeadBranches.php

Zuletzt modifiziert: 01.05.2026, 11:28 - Dateigröße: 1.83 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\TemplateNormalizations;
 09   
 10  use DOMElement;
 11   
 12  class OptimizeChooseDeadBranches extends AbstractChooseOptimization
 13  {
 14      /**
 15      * Test whether given XPath expression is always false
 16      *
 17      * @param  string $expr
 18      * @return bool
 19      */
 20      protected function isAlwaysFalse($expr)
 21      {
 22          // Always false: empty strings, 0, or false()
 23          $regexp = '(^(?:""|\'\'|(?:0*\\.)?0+|false\\s*\\(\\s*\\))$)';
 24   
 25          return (bool) preg_match($regexp, trim($expr));
 26      }
 27   
 28      /**
 29      * Test whether given XPath expression is always true
 30      *
 31      * @param  string $expr
 32      * @return bool
 33      */
 34      protected function isAlwaysTrue($expr)
 35      {
 36          // Always true: non-empty strings, non-0 numbers, or true()
 37          $regexp = '(^(?:"[^"]++"|\'[^\']++\'|0*[1-9][0-9]*(?:\\.[0-9]*)?|0*\\.0*[1-9][0-9]*|true\\s*\\(\\s*\\))$)';
 38   
 39          return (bool) preg_match($regexp, trim($expr));
 40      }
 41   
 42      /**
 43      * Convert given xsl:when element into an xsl:otherwise element
 44      *
 45      * @param  DOMElement $when
 46      * @return void
 47      */
 48      protected function makeOtherwise(DOMElement $when)
 49      {
 50          $otherwise = $this->createElement('xsl:otherwise');
 51          while ($when->firstChild)
 52          {
 53              $otherwise->appendChild($when->firstChild);
 54          }
 55   
 56          $when->parentNode->replaceChild($otherwise, $when);
 57      }
 58   
 59      /**
 60      * {@inheritdoc}
 61      */
 62      protected function optimizeChoose()
 63      {
 64          $removeAll = false;
 65          $tests     = [];
 66          foreach ($this->getBranches() as $branch)
 67          {
 68              $test = trim($branch->getAttribute('test'));
 69   
 70              if ($removeAll || isset($tests[$test]) || $this->isAlwaysFalse($test))
 71              {
 72                  $branch->parentNode->removeChild($branch);
 73              }
 74              elseif ($this->isAlwaysTrue($test))
 75              {
 76                  $removeAll = true;
 77                  $this->makeOtherwise($branch);
 78              }
 79   
 80              $tests[$test] = 1;
 81          }
 82      }
 83  }