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 |
IniGetWrapper.php
001 <?php
002
003 /*
004 * (c) Andreas Fischer <git@andreasfischer.net>
005 *
006 * For the full copyright and license information, please view the LICENSE
007 * file that was distributed with this source code.
008 */
009
010 namespace bantu\IniGetWrapper;
011
012 /**
013 * Wrapper class around built-in ini_get() function.
014 *
015 * Provides easier handling of the different interpretations of ini values.
016 */
017 class IniGetWrapper
018 {
019 /**
020 * Simple wrapper around ini_get()
021 * See http://php.net/manual/en/function.ini-get.php
022 *
023 * @param string $varname The configuration option name.
024 * @return null|string Null if configuration option does not exist.
025 * The configuration option value (string) otherwise.
026 */
027 public function get($varname)
028 {
029 $value = $this->getPhp($varname);
030 return $value === false ? null : $value;
031 }
032
033 /**
034 * Gets the configuration option value as a trimmed string.
035 *
036 * @param string $varname The configuration option name.
037 * @return null|string Null if configuration option does not exist.
038 * The configuration option value (string) otherwise.
039 */
040 public function getString($varname)
041 {
042 $value = $this->get($varname);
043 return $value === null ? null : trim($value);
044 }
045
046 /**
047 * Gets configuration option value as a boolean.
048 * Interprets the string value 'off' as false.
049 *
050 * @param string $varname The configuration option name.
051 * @return null|bool Null if configuration option does not exist.
052 * False if configuration option is disabled.
053 * True otherwise.
054 */
055 public function getBool($varname)
056 {
057 $value = $this->getString($varname);
058 return $value === null ? null : $value && strtolower($value) !== 'off';
059 }
060
061 /**
062 * Gets configuration option value as an integer.
063 *
064 * @param string $varname The configuration option name.
065 * @return null|int|float Null if configuration option does not exist or is not numeric.
066 * The configuration option value (integer or float) otherwise.
067 */
068 public function getNumeric($varname)
069 {
070 $value = $this->getString($varname);
071 return is_numeric($value) ? $value + 0 : null;
072 }
073
074 /**
075 * Gets configuration option value in bytes.
076 * Converts strings like '128M' to bytes (integer or float).
077 *
078 * @param string $varname The configuration option name.
079 * @return null|int|float Null if configuration option does not exist or is not well-formed.
080 * The configuration option value as bytes (integer or float) otherwise.
081 */
082 public function getBytes($varname)
083 {
084 $value = $this->getString($varname);
085
086 if ($value === null) {
087 return null;
088 }
089
090 if (is_numeric($value)) {
091 // Already in bytes.
092 return $value + 0;
093 }
094
095 if (strlen($value) < 2 || strlen($value) < 3 && $value[0] === '-') {
096 // Either a single character
097 // or two characters where the first one is a minus.
098 return null;
099 }
100
101 // Split string into numeric value and unit.
102 $value_numeric = substr($value, 0, -1);
103 if (!is_numeric($value_numeric)) {
104 return null;
105 }
106
107 switch (strtolower($value[strlen($value) - 1])) {
108 case 'g':
109 $value_numeric *= 1024;
110 // no break
111 case 'm':
112 $value_numeric *= 1024;
113 // no break
114 case 'k':
115 $value_numeric *= 1024;
116 break;
117
118 default:
119 // It's not already in bytes (and thus numeric)
120 // and does not carry a unit.
121 return null;
122 }
123
124 return $value_numeric;
125 }
126
127 /**
128 * Gets configuration option value as a list (array).
129 * Converts comma-separated string into list (array).
130 *
131 * @param string $varname The configuration option name.
132 * @return null|array Null if configuration option does not exist.
133 * The configuration option value as a list (array) otherwise.
134 */
135 public function getList($varname)
136 {
137 $value = $this->getString($varname);
138 return $value === null ? null : explode(',', $value);
139 }
140
141 /**
142 * Checks whether a list contains a given element (string).
143 *
144 * @param string $varname The configuration option name.
145 * @param string $needle The element to check whether it is contained in the list.
146 * @return null|bool Null if configuration option does not exist.
147 * Whether $needle is contained in the list otherwise.
148 */
149 public function listContains($varname, $needle)
150 {
151 $list = $this->getList($varname);
152 return $list === null ? null : in_array($needle, $list, true);
153 }
154
155 /**
156 * @param string $varname The configuration option name.
157 */
158 protected function getPhp($varname)
159 {
160 return ini_get($varname);
161 }
162 }
163