Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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

Terminal.php

Zuletzt modifiziert: 02.04.2025, 15:02 - Dateigröße: 4.96 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;
013   
014  class Terminal
015  {
016      private static $width;
017      private static $height;
018      private static $stty;
019   
020      /**
021       * Gets the terminal width.
022       *
023       * @return int
024       */
025      public function getWidth()
026      {
027          $width = getenv('COLUMNS');
028          if (false !== $width) {
029              return (int) trim($width);
030          }
031   
032          if (null === self::$width) {
033              self::initDimensions();
034          }
035   
036          return self::$width ?: 80;
037      }
038   
039      /**
040       * Gets the terminal height.
041       *
042       * @return int
043       */
044      public function getHeight()
045      {
046          $height = getenv('LINES');
047          if (false !== $height) {
048              return (int) trim($height);
049          }
050   
051          if (null === self::$height) {
052              self::initDimensions();
053          }
054   
055          return self::$height ?: 50;
056      }
057   
058      /**
059       * @internal
060       *
061       * @return bool
062       */
063      public static function hasSttyAvailable()
064      {
065          if (null !== self::$stty) {
066              return self::$stty;
067          }
068   
069          // skip check if exec function is disabled
070          if (!\function_exists('exec')) {
071              return false;
072          }
073   
074          exec('stty 2>&1', $output, $exitcode);
075   
076          return self::$stty = 0 === $exitcode;
077      }
078   
079      private static function initDimensions()
080      {
081          if ('\\' === \DIRECTORY_SEPARATOR) {
082              if (preg_match('/^(\d+)x(\d+)(?: \((\d+)x(\d+)\))?$/', trim(getenv('ANSICON')), $matches)) {
083                  // extract [w, H] from "wxh (WxH)"
084                  // or [w, h] from "wxh"
085                  self::$width = (int) $matches[1];
086                  self::$height = isset($matches[4]) ? (int) $matches[4] : (int) $matches[2];
087              } elseif (!self::hasVt100Support() && self::hasSttyAvailable()) {
088                  // only use stty on Windows if the terminal does not support vt100 (e.g. Windows 7 + git-bash)
089                  // testing for stty in a Windows 10 vt100-enabled console will implicitly disable vt100 support on STDOUT
090                  self::initDimensionsUsingStty();
091              } elseif (null !== $dimensions = self::getConsoleMode()) {
092                  // extract [w, h] from "wxh"
093                  self::$width = (int) $dimensions[0];
094                  self::$height = (int) $dimensions[1];
095              }
096          } else {
097              self::initDimensionsUsingStty();
098          }
099      }
100   
101      /**
102       * Returns whether STDOUT has vt100 support (some Windows 10+ configurations).
103       */
104      private static function hasVt100Support()
105      {
106          return \function_exists('sapi_windows_vt100_support') && sapi_windows_vt100_support(fopen('php://stdout', 'w'));
107      }
108   
109      /**
110       * Initializes dimensions using the output of an stty columns line.
111       */
112      private static function initDimensionsUsingStty()
113      {
114          if ($sttyString = self::getSttyColumns()) {
115              if (preg_match('/rows.(\d+);.columns.(\d+);/i', $sttyString, $matches)) {
116                  // extract [w, h] from "rows h; columns w;"
117                  self::$width = (int) $matches[2];
118                  self::$height = (int) $matches[1];
119              } elseif (preg_match('/;.(\d+).rows;.(\d+).columns/i', $sttyString, $matches)) {
120                  // extract [w, h] from "; h rows; w columns"
121                  self::$width = (int) $matches[2];
122                  self::$height = (int) $matches[1];
123              }
124          }
125      }
126   
127      /**
128       * Runs and parses mode CON if it's available, suppressing any error output.
129       *
130       * @return int[]|null An array composed of the width and the height or null if it could not be parsed
131       */
132      private static function getConsoleMode()
133      {
134          $info = self::readFromProcess('mode CON');
135   
136          if (null === $info || !preg_match('/--------+\r?\n.+?(\d+)\r?\n.+?(\d+)\r?\n/', $info, $matches)) {
137              return null;
138          }
139   
140          return [(int) $matches[2], (int) $matches[1]];
141      }
142   
143      /**
144       * Runs and parses stty -a if it's available, suppressing any error output.
145       *
146       * @return string|null
147       */
148      private static function getSttyColumns()
149      {
150          return self::readFromProcess('stty -a | grep columns');
151      }
152   
153      /**
154       * @param string $command
155       *
156       * @return string|null
157       */
158      private static function readFromProcess($command)
159      {
160          if (!\function_exists('proc_open')) {
161              return null;
162          }
163   
164          $descriptorspec = [
165              1 => ['pipe', 'w'],
166              2 => ['pipe', 'w'],
167          ];
168   
169          $process = proc_open($command, $descriptorspec, $pipes, null, null, ['suppress_errors' => true]);
170          if (!\is_resource($process)) {
171              return null;
172          }
173   
174          $info = stream_get_contents($pipes[1]);
175          fclose($pipes[1]);
176          fclose($pipes[2]);
177          proc_close($process);
178   
179          return $info;
180      }
181  }
182