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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
Helper.php
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\Helper;
013
014 use Symfony\Component\Console\Formatter\OutputFormatterInterface;
015
016 /**
017 * Helper is the base class for all helper classes.
018 *
019 * @author Fabien Potencier <fabien@symfony.com>
020 */
021 abstract class Helper implements HelperInterface
022 {
023 protected $helperSet = null;
024
025 /**
026 * {@inheritdoc}
027 */
028 public function setHelperSet(HelperSet $helperSet = null)
029 {
030 $this->helperSet = $helperSet;
031 }
032
033 /**
034 * {@inheritdoc}
035 */
036 public function getHelperSet()
037 {
038 return $this->helperSet;
039 }
040
041 /**
042 * Returns the length of a string, using mb_strwidth if it is available.
043 *
044 * @param string $string The string to check its length
045 *
046 * @return int The length of the string
047 */
048 public static function strlen($string)
049 {
050 if (false === $encoding = mb_detect_encoding($string, null, true)) {
051 return \strlen($string);
052 }
053
054 return mb_strwidth($string, $encoding);
055 }
056
057 /**
058 * Returns the subset of a string, using mb_substr if it is available.
059 *
060 * @param string $string String to subset
061 * @param int $from Start offset
062 * @param int|null $length Length to read
063 *
064 * @return string The string subset
065 */
066 public static function substr($string, $from, $length = null)
067 {
068 if (false === $encoding = mb_detect_encoding($string, null, true)) {
069 return substr($string, $from, $length);
070 }
071
072 return mb_substr($string, $from, $length, $encoding);
073 }
074
075 public static function formatTime($secs)
076 {
077 static $timeFormats = [
078 [0, '< 1 sec'],
079 [1, '1 sec'],
080 [2, 'secs', 1],
081 [60, '1 min'],
082 [120, 'mins', 60],
083 [3600, '1 hr'],
084 [7200, 'hrs', 3600],
085 [86400, '1 day'],
086 [172800, 'days', 86400],
087 ];
088
089 foreach ($timeFormats as $index => $format) {
090 if ($secs >= $format[0]) {
091 if ((isset($timeFormats[$index + 1]) && $secs < $timeFormats[$index + 1][0])
092 || $index == \count($timeFormats) - 1
093 ) {
094 if (2 == \count($format)) {
095 return $format[1];
096 }
097
098 return floor($secs / $format[2]).' '.$format[1];
099 }
100 }
101 }
102 }
103
104 public static function formatMemory($memory)
105 {
106 if ($memory >= 1024 * 1024 * 1024) {
107 return sprintf('%.1f GiB', $memory / 1024 / 1024 / 1024);
108 }
109
110 if ($memory >= 1024 * 1024) {
111 return sprintf('%.1f MiB', $memory / 1024 / 1024);
112 }
113
114 if ($memory >= 1024) {
115 return sprintf('%d KiB', $memory / 1024);
116 }
117
118 return sprintf('%d B', $memory);
119 }
120
121 public static function strlenWithoutDecoration(OutputFormatterInterface $formatter, $string)
122 {
123 return self::strlen(self::removeDecoration($formatter, $string));
124 }
125
126 public static function removeDecoration(OutputFormatterInterface $formatter, $string)
127 {
128 $isDecorated = $formatter->isDecorated();
129 $formatter->setDecorated(false);
130 // remove <...> formatting
131 $string = $formatter->format($string);
132 // remove already formatted characters
133 $string = preg_replace("/\033\[[^m]*m/", '', $string);
134 $formatter->setDecorated($isDecorated);
135
136 return $string;
137 }
138 }
139