Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
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 |
Regex.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\Finder\Expression;
013
014 @trigger_error('The '.__NAMESPACE__.'\Regex class is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
015
016 /**
017 * @author Jean-François Simon <contact@jfsimon.fr>
018 */
019 class Regex implements ValueInterface
020 {
021 const START_FLAG = '^';
022 const END_FLAG = '$';
023 const BOUNDARY = '~';
024 const JOKER = '.*';
025 const ESCAPING = '\\';
026
027 /**
028 * @var string
029 */
030 private $pattern;
031
032 /**
033 * @var array
034 */
035 private $options;
036
037 /**
038 * @var bool
039 */
040 private $startFlag;
041
042 /**
043 * @var bool
044 */
045 private $endFlag;
046
047 /**
048 * @var bool
049 */
050 private $startJoker;
051
052 /**
053 * @var bool
054 */
055 private $endJoker;
056
057 /**
058 * @param string $expr
059 *
060 * @return Regex
061 *
062 * @throws \InvalidArgumentException
063 */
064 public static function create($expr)
065 {
066 if (preg_match('/^(.{3,}?)([imsxuADU]*)$/', $expr, $m)) {
067 $start = substr($m[1], 0, 1);
068 $end = substr($m[1], -1);
069
070 if (
071 ($start === $end && !preg_match('/[*?[:alnum:] \\\\]/', $start))
072 || ($start === '{' && $end === '}')
073 || ($start === '(' && $end === ')')
074 ) {
075 return new self(substr($m[1], 1, -1), $m[2], $end);
076 }
077 }
078
079 throw new \InvalidArgumentException('Given expression is not a regex.');
080 }
081
082 /**
083 * @param string $pattern
084 * @param string $options
085 * @param string $delimiter
086 */
087 public function __construct($pattern, $options = '', $delimiter = null)
088 {
089 if (null !== $delimiter) {
090 // removes delimiter escaping
091 $pattern = str_replace('\\'.$delimiter, $delimiter, $pattern);
092 }
093
094 $this->parsePattern($pattern);
095 $this->options = $options;
096 }
097
098 /**
099 * @return string
100 */
101 public function __toString()
102 {
103 return $this->render();
104 }
105
106 /**
107 * {@inheritdoc}
108 */
109 public function render()
110 {
111 return self::BOUNDARY
112 .$this->renderPattern()
113 .self::BOUNDARY
114 .$this->options;
115 }
116
117 /**
118 * {@inheritdoc}
119 */
120 public function renderPattern()
121 {
122 return ($this->startFlag ? self::START_FLAG : '')
123 .($this->startJoker ? self::JOKER : '')
124 .str_replace(self::BOUNDARY, '\\'.self::BOUNDARY, $this->pattern)
125 .($this->endJoker ? self::JOKER : '')
126 .($this->endFlag ? self::END_FLAG : '');
127 }
128
129 /**
130 * {@inheritdoc}
131 */
132 public function isCaseSensitive()
133 {
134 return !$this->hasOption('i');
135 }
136
137 /**
138 * {@inheritdoc}
139 */
140 public function getType()
141 {
142 return Expression::TYPE_REGEX;
143 }
144
145 /**
146 * {@inheritdoc}
147 */
148 public function prepend($expr)
149 {
150 $this->pattern = $expr.$this->pattern;
151
152 return $this;
153 }
154
155 /**
156 * {@inheritdoc}
157 */
158 public function append($expr)
159 {
160 $this->pattern .= $expr;
161
162 return $this;
163 }
164
165 /**
166 * @param string $option
167 *
168 * @return bool
169 */
170 public function hasOption($option)
171 {
172 return false !== strpos($this->options, $option);
173 }
174
175 /**
176 * @param string $option
177 *
178 * @return Regex
179 */
180 public function addOption($option)
181 {
182 if (!$this->hasOption($option)) {
183 $this->options .= $option;
184 }
185
186 return $this;
187 }
188
189 /**
190 * @param string $option
191 *
192 * @return Regex
193 */
194 public function removeOption($option)
195 {
196 $this->options = str_replace($option, '', $this->options);
197
198 return $this;
199 }
200
201 /**
202 * @param bool $startFlag
203 *
204 * @return Regex
205 */
206 public function setStartFlag($startFlag)
207 {
208 $this->startFlag = $startFlag;
209
210 return $this;
211 }
212
213 /**
214 * @return bool
215 */
216 public function hasStartFlag()
217 {
218 return $this->startFlag;
219 }
220
221 /**
222 * @param bool $endFlag
223 *
224 * @return Regex
225 */
226 public function setEndFlag($endFlag)
227 {
228 $this->endFlag = (bool) $endFlag;
229
230 return $this;
231 }
232
233 /**
234 * @return bool
235 */
236 public function hasEndFlag()
237 {
238 return $this->endFlag;
239 }
240
241 /**
242 * @param bool $startJoker
243 *
244 * @return Regex
245 */
246 public function setStartJoker($startJoker)
247 {
248 $this->startJoker = $startJoker;
249
250 return $this;
251 }
252
253 /**
254 * @return bool
255 */
256 public function hasStartJoker()
257 {
258 return $this->startJoker;
259 }
260
261 /**
262 * @param bool $endJoker
263 *
264 * @return Regex
265 */
266 public function setEndJoker($endJoker)
267 {
268 $this->endJoker = (bool) $endJoker;
269
270 return $this;
271 }
272
273 /**
274 * @return bool
275 */
276 public function hasEndJoker()
277 {
278 return $this->endJoker;
279 }
280
281 /**
282 * @param array $replacement
283 *
284 * @return Regex
285 */
286 public function replaceJokers($replacement)
287 {
288 $replace = function ($subject) use ($replacement) {
289 $subject = $subject[0];
290 $replace = 0 === substr_count($subject, '\\') % 2;
291
292 return $replace ? str_replace('.', $replacement, $subject) : $subject;
293 };
294
295 $this->pattern = preg_replace_callback('~[\\\\]*\\.~', $replace, $this->pattern);
296
297 return $this;
298 }
299
300 /**
301 * @param string $pattern
302 */
303 private function parsePattern($pattern)
304 {
305 if ($this->startFlag = self::START_FLAG === substr($pattern, 0, 1)) {
306 $pattern = substr($pattern, 1);
307 }
308
309 if ($this->startJoker = self::JOKER === substr($pattern, 0, 2)) {
310 $pattern = substr($pattern, 2);
311 }
312
313 if ($this->endFlag = (self::END_FLAG === substr($pattern, -1) && self::ESCAPING !== substr($pattern, -2, -1))) {
314 $pattern = substr($pattern, 0, -1);
315 }
316
317 if ($this->endJoker = (self::JOKER === substr($pattern, -2) && self::ESCAPING !== substr($pattern, -3, -2))) {
318 $pattern = substr($pattern, 0, -2);
319 }
320
321 $this->pattern = $pattern;
322 }
323 }
324