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

OutputFormatter.php

Zuletzt modifiziert: 01.05.2026, 11:27 - Dateigröße: 6.66 KiB


 001  <?php
 002   
 003  /*
 004   * This file is part of the Symfony package.
 005   *
 006   * (c) Fabien Potencier <fabien@symfony.com>
 007   *
 008   * For the full copyright and license information, please view the LICENSE
 009   * file that was distributed with this source code.
 010   */
 011   
 012  namespace Symfony\Component\Console\Formatter;
 013   
 014  use Symfony\Component\Console\Exception\InvalidArgumentException;
 015   
 016  /**
 017   * Formatter class for console output.
 018   *
 019   * @author Konstantin Kudryashov <ever.zet@gmail.com>
 020   */
 021  class OutputFormatter implements OutputFormatterInterface
 022  {
 023      private $decorated;
 024      private $styles = [];
 025      private $styleStack;
 026   
 027      /**
 028       * Escapes "<" special char in given text.
 029       *
 030       * @param string $text Text to escape
 031       *
 032       * @return string Escaped text
 033       */
 034      public static function escape($text)
 035      {
 036          $text = preg_replace('/([^\\\\]?)</', '$1\\<', $text);
 037   
 038          return self::escapeTrailingBackslash($text);
 039      }
 040   
 041      /**
 042       * Escapes trailing "\" in given text.
 043       *
 044       * @param string $text Text to escape
 045       *
 046       * @return string Escaped text
 047       *
 048       * @internal
 049       */
 050      public static function escapeTrailingBackslash($text)
 051      {
 052          if ('\\' === substr($text, -1)) {
 053              $len = \strlen($text);
 054              $text = rtrim($text, '\\');
 055              $text = str_replace("\0", '', $text);
 056              $text .= str_repeat("\0", $len - \strlen($text));
 057          }
 058   
 059          return $text;
 060      }
 061   
 062      /**
 063       * Initializes console output formatter.
 064       *
 065       * @param bool                            $decorated Whether this formatter should actually decorate strings
 066       * @param OutputFormatterStyleInterface[] $styles    Array of "name => FormatterStyle" instances
 067       */
 068      public function __construct($decorated = false, array $styles = [])
 069      {
 070          $this->decorated = (bool) $decorated;
 071   
 072          $this->setStyle('error', new OutputFormatterStyle('white', 'red'));
 073          $this->setStyle('info', new OutputFormatterStyle('green'));
 074          $this->setStyle('comment', new OutputFormatterStyle('yellow'));
 075          $this->setStyle('question', new OutputFormatterStyle('black', 'cyan'));
 076   
 077          foreach ($styles as $name => $style) {
 078              $this->setStyle($name, $style);
 079          }
 080   
 081          $this->styleStack = new OutputFormatterStyleStack();
 082      }
 083   
 084      /**
 085       * {@inheritdoc}
 086       */
 087      public function setDecorated($decorated)
 088      {
 089          $this->decorated = (bool) $decorated;
 090      }
 091   
 092      /**
 093       * {@inheritdoc}
 094       */
 095      public function isDecorated()
 096      {
 097          return $this->decorated;
 098      }
 099   
 100      /**
 101       * {@inheritdoc}
 102       */
 103      public function setStyle($name, OutputFormatterStyleInterface $style)
 104      {
 105          $this->styles[strtolower($name)] = $style;
 106      }
 107   
 108      /**
 109       * {@inheritdoc}
 110       */
 111      public function hasStyle($name)
 112      {
 113          return isset($this->styles[strtolower($name)]);
 114      }
 115   
 116      /**
 117       * {@inheritdoc}
 118       */
 119      public function getStyle($name)
 120      {
 121          if (!$this->hasStyle($name)) {
 122              throw new InvalidArgumentException(sprintf('Undefined style: "%s".', $name));
 123          }
 124   
 125          return $this->styles[strtolower($name)];
 126      }
 127   
 128      /**
 129       * {@inheritdoc}
 130       */
 131      public function format($message)
 132      {
 133          $message = (string) $message;
 134          $offset = 0;
 135          $output = '';
 136          $tagRegex = '[a-z][a-z0-9,_=;-]*+';
 137          preg_match_all("#<(($tagRegex) | /($tagRegex)?)>#ix", $message, $matches, \PREG_OFFSET_CAPTURE);
 138          foreach ($matches[0] as $i => $match) {
 139              $pos = $match[1];
 140              $text = $match[0];
 141   
 142              if (0 != $pos && '\\' == $message[$pos - 1]) {
 143                  continue;
 144              }
 145   
 146              // add the text up to the next tag
 147              $output .= $this->applyCurrentStyle(substr($message, $offset, $pos - $offset));
 148              $offset = $pos + \strlen($text);
 149   
 150              // opening tag?
 151              if ($open = '/' != $text[1]) {
 152                  $tag = $matches[1][$i][0];
 153              } else {
 154                  $tag = isset($matches[3][$i][0]) ? $matches[3][$i][0] : '';
 155              }
 156   
 157              if (!$open && !$tag) {
 158                  // </>
 159                  $this->styleStack->pop();
 160              } elseif (false === $style = $this->createStyleFromString($tag)) {
 161                  $output .= $this->applyCurrentStyle($text);
 162              } elseif ($open) {
 163                  $this->styleStack->push($style);
 164              } else {
 165                  $this->styleStack->pop($style);
 166              }
 167          }
 168   
 169          $output .= $this->applyCurrentStyle(substr($message, $offset));
 170   
 171          if (false !== strpos($output, "\0")) {
 172              return strtr($output, ["\0" => '\\', '\\<' => '<']);
 173          }
 174   
 175          return str_replace('\\<', '<', $output);
 176      }
 177   
 178      /**
 179       * @return OutputFormatterStyleStack
 180       */
 181      public function getStyleStack()
 182      {
 183          return $this->styleStack;
 184      }
 185   
 186      /**
 187       * Tries to create new style instance from string.
 188       *
 189       * @param string $string
 190       *
 191       * @return OutputFormatterStyle|false false if string is not format string
 192       */
 193      private function createStyleFromString($string)
 194      {
 195          if (isset($this->styles[$string])) {
 196              return $this->styles[$string];
 197          }
 198   
 199          if (!preg_match_all('/([^=]+)=([^;]+)(;|$)/', $string, $matches, \PREG_SET_ORDER)) {
 200              return false;
 201          }
 202   
 203          $style = new OutputFormatterStyle();
 204          foreach ($matches as $match) {
 205              array_shift($match);
 206              $match[0] = strtolower($match[0]);
 207   
 208              if ('fg' == $match[0]) {
 209                  $style->setForeground(strtolower($match[1]));
 210              } elseif ('bg' == $match[0]) {
 211                  $style->setBackground(strtolower($match[1]));
 212              } elseif ('options' === $match[0]) {
 213                  preg_match_all('([^,;]+)', strtolower($match[1]), $options);
 214                  $options = array_shift($options);
 215                  foreach ($options as $option) {
 216                      try {
 217                          $style->setOption($option);
 218                      } catch (\InvalidArgumentException $e) {
 219                          @trigger_error(sprintf('Unknown style options are deprecated since Symfony 3.2 and will be removed in 4.0. Exception "%s".', $e->getMessage()), \E_USER_DEPRECATED);
 220   
 221                          return false;
 222                      }
 223                  }
 224              } else {
 225                  return false;
 226              }
 227          }
 228   
 229          return $style;
 230      }
 231   
 232      /**
 233       * Applies current style from stack to text, if must be applied.
 234       *
 235       * @param string $text Input text
 236       *
 237       * @return string Styled text
 238       */
 239      private function applyCurrentStyle($text)
 240      {
 241          return $this->isDecorated() && \strlen($text) > 0 ? $this->styleStack->getCurrent()->apply($text) : $text;
 242      }
 243  }
 244