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 |
FilterSyntaxMatcher.php
001 <?php declare(strict_types=1);
002
003 /**
004 * @package s9e\TextFormatter
005 * @copyright Copyright (c) 2010-2022 The s9e authors
006 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
007 */
008 namespace s9e\TextFormatter\Configurator\Helpers;
009
010 use s9e\TextFormatter\Configurator\Items\Regexp;
011 use s9e\TextFormatter\Configurator\RecursiveParser\AbstractRecursiveMatcher;
012
013 class FilterSyntaxMatcher extends AbstractRecursiveMatcher
014 {
015 /**
016 * {@inheritdoc}
017 */
018 public function getMatchers(): array
019 {
020 return [
021 'Array' => [
022 'groups' => ['FilterArg', 'Literal'],
023 'regexp' => '\\[ ((?&ArrayElements))? \\]',
024 ],
025 'ArrayElement' => [
026 'regexp' => '(?:((?&Scalar)) => )?((?&Literal))',
027 ],
028 'ArrayElements' => [
029 'regexp' => '((?&ArrayElement))(?: , ((?&ArrayElements)))?',
030 ],
031 'DoubleQuotedString' => [
032 'groups' => ['FilterArg', 'Literal', 'Scalar'],
033 'regexp' => '"((?:[^\\\\"]|\\\\.)*)"',
034 ],
035 'False' => [
036 'groups' => ['FilterArg', 'Literal', 'Scalar'],
037 'regexp' => '[Ff][Aa][Ll][Ss][Ee]',
038 ],
039 'FilterArgs' => [
040 'regexp' => '((?&FilterArg))(?: , ((?&FilterArgs)))?',
041 ],
042 'FilterCallback' => [
043 'regexp' => '([#:\\\\\\w]+)(?: \\( ((?&FilterArgs)?) \\))?',
044 ],
045 'Float' => [
046 'groups' => ['FilterArg', 'Literal', 'Scalar'],
047 'regexp' => '([-+]?(?:\\.[0-9]+(?:_[0-9]+)*|[0-9]+(?:_[0-9]+)*\\.(?!_)[0-9]*(?:_[0-9]+)*|[0-9]+(?:_[0-9]+)*(?=[Ee]))(?:[Ee]-?[0-9]+(?:_[0-9]+)*)?)',
048 ],
049 'Integer' => [
050 'groups' => ['FilterArg', 'Literal', 'Scalar'],
051 'regexp' => '(-?(?:0[Bb][01]+(?:_[01]+)*|0[Oo][0-7]+(?:_[0-7]+)*|0[Xx][0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*|[0-9]+(?:_[0-9]+)*))',
052 ],
053 'Null' => [
054 'groups' => ['FilterArg', 'Literal', 'Scalar'],
055 'regexp' => '[Nn][Uu][Ll][Ll]',
056 ],
057 'Param' => [
058 'groups' => ['FilterArg'],
059 'regexp' => '\\$(\\w+(?:\\.\\w+)*)',
060 ],
061 'Regexp' => [
062 'groups' => ['FilterArg', 'Literal'],
063 'regexp' => '(/(?:[^\\\\/]|\\\\.)*/)([Sgimsu]*)',
064 ],
065 'SingleQuotedString' => [
066 'groups' => ['FilterArg', 'Literal', 'Scalar'],
067 'regexp' => "'((?:[^\\\\']|\\\\.)*)'",
068 ],
069 'True' => [
070 'groups' => ['FilterArg', 'Literal', 'Scalar'],
071 'regexp' => '[Tt][Rr][Uu][Ee]'
072 ]
073 ];
074 }
075
076 /**
077 * @param string $elements
078 * @return array
079 */
080 public function parseArray(string $elements = ''): array
081 {
082 $array = [];
083 if ($elements !== '')
084 {
085 foreach ($this->recurse($elements, 'ArrayElements') as $element)
086 {
087 if (array_key_exists('key', $element))
088 {
089 $array[$element['key']] = $element['value'];
090 }
091 else
092 {
093 $array[] = $element['value'];
094 }
095 }
096 }
097
098 return $array;
099 }
100
101 /**
102 * @param string $key
103 * @param string $value
104 * @return array
105 */
106 public function parseArrayElement(string $key, string $value): array
107 {
108 $element = ['value' => $this->recurse($value, 'Literal')];
109 if ($key !== '')
110 {
111 $element['key'] = $this->recurse($key, 'Scalar');
112 }
113
114 return $element;
115 }
116
117 /**
118 * @param string $firstElement
119 * @param string $otherElements
120 * @return array
121 */
122 public function parseArrayElements(string $firstElement, string $otherElements = null)
123 {
124 $elements = [$this->recurse($firstElement, 'ArrayElement')];
125 if (isset($otherElements))
126 {
127 $elements = array_merge($elements, $this->recurse($otherElements, 'ArrayElements'));
128 }
129
130 return $elements;
131 }
132
133 /**
134 * @param string $str
135 * @return string
136 */
137 public function parseDoubleQuotedString(string $str): string
138 {
139 /**
140 * @link https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.double
141 */
142 return preg_replace_callback(
143 '(\\\\([nrtvef\\\\$"]|[0-7]{1,3}|x[0-9A-Fa-f]{1,2}|u\\{[0-9A-Fa-f]+\\}))',
144 function ($m)
145 {
146 if ($m[1] === 'e')
147 {
148 return "\e";
149 }
150 if ($m[1][0] === 'u')
151 {
152 return html_entity_decode('&#x' . substr($m[1], 2, -1) . ';', ENT_QUOTES, 'utf-8');
153 }
154
155 return stripcslashes($m[0]);
156 },
157 $str
158 );
159 }
160
161 /**
162 * @return bool
163 */
164 public function parseFalse(): bool
165 {
166 return false;
167 }
168
169 /**
170 * @param string $callback
171 * @param string $args
172 * @return array
173 */
174 public function parseFilterCallback(string $callback, string $args = null): array
175 {
176 $config = ['filter' => $callback];
177 if (isset($args))
178 {
179 $config['params'] = ($args === '') ? [] : $this->recurse($args, 'FilterArgs');
180 }
181
182 return $config;
183 }
184
185 /**
186 * @param string $firstArg
187 * @param string $otherArgs
188 * @return array
189 */
190 public function parseFilterArgs(string $firstArg, string $otherArgs = null)
191 {
192 $parsedArg = $this->parser->parse($firstArg, 'FilterArg');
193
194 $type = ($parsedArg['match'] === 'Param') ? 'Name' : 'Value';
195 $args = [[$type, $parsedArg['value']]];
196 if (isset($otherArgs))
197 {
198 $args = array_merge($args, $this->recurse($otherArgs, 'FilterArgs'));
199 }
200
201 return $args;
202 }
203
204 /**
205 * @return null
206 */
207 public function parseNull()
208 {
209 return null;
210 }
211
212 /**
213 * @param string $str
214 * @return float
215 */
216 public function parseFloat(string $str): float
217 {
218 return (float) str_replace('_', '', $str);
219 }
220
221 /**
222 * @param string $str
223 * @return integer
224 */
225 public function parseInteger(string $str): int
226 {
227 // Handle PHP 8.1's explicit octal notation
228 if (strtolower(substr($str, 0, 2)) === '0o')
229 {
230 $str = '0' . substr($str, 2);
231 }
232
233 return intval(str_replace('_', '', $str), 0);
234 }
235
236 /**
237 * @param string $str
238 * @return string
239 */
240 public function parseParam(string $str): string
241 {
242 return $str;
243 }
244
245 /**
246 * @param string $regexp
247 * @param string $flags
248 * @return Regexp
249 */
250 public function parseRegexp(string $regexp, string $flags): Regexp
251 {
252 $regexp .= str_replace('g', '', $flags);
253
254 return new Regexp($regexp, true);
255 }
256
257 /**
258 * @param string $str
259 * @return string
260 */
261 public function parseSingleQuotedString(string $str): string
262 {
263 return preg_replace("(\\\\([\\\\']))", '$1', $str);
264 }
265
266 /**
267 * @return bool
268 */
269 public function parseTrue(): bool
270 {
271 return true;
272 }
273 }