@@ -55,45 +55,45 @@ discard block |
||
55 | 55 | const ERROR_EMPTY_DELIMITER = 47803; |
56 | 56 | const ERROR_PLACEHOLDER_NOT_FOUND = 47804; |
57 | 57 | |
58 | - /** |
|
59 | - * @var Mailcode_Parser |
|
60 | - */ |
|
58 | + /** |
|
59 | + * @var Mailcode_Parser |
|
60 | + */ |
|
61 | 61 | protected $parser; |
62 | 62 | |
63 | - /** |
|
64 | - * @var Mailcode_Collection |
|
65 | - */ |
|
63 | + /** |
|
64 | + * @var Mailcode_Collection |
|
65 | + */ |
|
66 | 66 | protected $commands; |
67 | 67 | |
68 | - /** |
|
69 | - * @var string |
|
70 | - */ |
|
68 | + /** |
|
69 | + * @var string |
|
70 | + */ |
|
71 | 71 | protected $originalString; |
72 | 72 | |
73 | - /** |
|
74 | - * @var Mailcode_Collection |
|
75 | - */ |
|
73 | + /** |
|
74 | + * @var Mailcode_Collection |
|
75 | + */ |
|
76 | 76 | protected $collection; |
77 | 77 | |
78 | - /** |
|
79 | - * Counter for the placeholders, global for all placeholders. |
|
80 | - * @var integer |
|
81 | - */ |
|
78 | + /** |
|
79 | + * Counter for the placeholders, global for all placeholders. |
|
80 | + * @var integer |
|
81 | + */ |
|
82 | 82 | private static $counter = 0; |
83 | 83 | |
84 | - /** |
|
85 | - * @var Mailcode_Parser_Safeguard_Placeholder[] |
|
86 | - */ |
|
84 | + /** |
|
85 | + * @var Mailcode_Parser_Safeguard_Placeholder[] |
|
86 | + */ |
|
87 | 87 | protected $placeholders; |
88 | 88 | |
89 | - /** |
|
90 | - * @var string |
|
91 | - */ |
|
89 | + /** |
|
90 | + * @var string |
|
91 | + */ |
|
92 | 92 | protected $delimiter = '__'; |
93 | 93 | |
94 | - /** |
|
95 | - * @var string[]|NULL |
|
96 | - */ |
|
94 | + /** |
|
95 | + * @var string[]|NULL |
|
96 | + */ |
|
97 | 97 | protected $placeholderStrings; |
98 | 98 | |
99 | 99 | public function __construct(Mailcode_Parser $parser, string $subject) |
@@ -102,25 +102,25 @@ discard block |
||
102 | 102 | $this->originalString = $subject; |
103 | 103 | } |
104 | 104 | |
105 | - /** |
|
106 | - * Retrieves the string the safeguard was created for. |
|
107 | - * |
|
108 | - * @return string |
|
109 | - */ |
|
105 | + /** |
|
106 | + * Retrieves the string the safeguard was created for. |
|
107 | + * |
|
108 | + * @return string |
|
109 | + */ |
|
110 | 110 | public function getOriginalString() : string |
111 | 111 | { |
112 | 112 | return $this->originalString; |
113 | 113 | } |
114 | 114 | |
115 | - /** |
|
116 | - * Sets the delimiter character sequence used to prepend |
|
117 | - * and append to the placeholders. |
|
118 | - * |
|
119 | - * The delimiter's default is "__" (two underscores). |
|
120 | - * |
|
121 | - * @param string $delimiter |
|
122 | - * @return Mailcode_Parser_Safeguard |
|
123 | - */ |
|
115 | + /** |
|
116 | + * Sets the delimiter character sequence used to prepend |
|
117 | + * and append to the placeholders. |
|
118 | + * |
|
119 | + * The delimiter's default is "__" (two underscores). |
|
120 | + * |
|
121 | + * @param string $delimiter |
|
122 | + * @return Mailcode_Parser_Safeguard |
|
123 | + */ |
|
124 | 124 | public function setDelimiter(string $delimiter) : Mailcode_Parser_Safeguard |
125 | 125 | { |
126 | 126 | if(empty($delimiter)) |
@@ -142,15 +142,15 @@ discard block |
||
142 | 142 | return $this->delimiter; |
143 | 143 | } |
144 | 144 | |
145 | - /** |
|
146 | - * Retrieves the safe string in which all commands have been replaced |
|
147 | - * by placeholder strings. |
|
148 | - * |
|
149 | - * @return string |
|
150 | - * @throws Mailcode_Exception |
|
151 | - * |
|
152 | - * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
153 | - */ |
|
145 | + /** |
|
146 | + * Retrieves the safe string in which all commands have been replaced |
|
147 | + * by placeholder strings. |
|
148 | + * |
|
149 | + * @return string |
|
150 | + * @throws Mailcode_Exception |
|
151 | + * |
|
152 | + * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
153 | + */ |
|
154 | 154 | public function makeSafe() : string |
155 | 155 | { |
156 | 156 | $this->requireValidCollection(); |
@@ -158,16 +158,16 @@ discard block |
||
158 | 158 | return $this->makeSafePartial(); |
159 | 159 | } |
160 | 160 | |
161 | - /** |
|
162 | - * Like makeSafe(), but allows partial (invalid) commands: use this |
|
163 | - * if the subject string may contain only part of the whole set of |
|
164 | - * commands. |
|
165 | - * |
|
166 | - * Example: parsing a text with an opening if statement, without the |
|
167 | - * matching end statement. |
|
168 | - * |
|
169 | - * @return string |
|
170 | - */ |
|
161 | + /** |
|
162 | + * Like makeSafe(), but allows partial (invalid) commands: use this |
|
163 | + * if the subject string may contain only part of the whole set of |
|
164 | + * commands. |
|
165 | + * |
|
166 | + * Example: parsing a text with an opening if statement, without the |
|
167 | + * matching end statement. |
|
168 | + * |
|
169 | + * @return string |
|
170 | + */ |
|
171 | 171 | public function makeSafePartial() : string |
172 | 172 | { |
173 | 173 | $placeholders = $this->getPlaceholders(); |
@@ -272,13 +272,13 @@ discard block |
||
272 | 272 | } |
273 | 273 | } |
274 | 274 | |
275 | - /** |
|
276 | - * Creates a formatting handler, which can be used to specify |
|
277 | - * which formattings to use for the commands in the subject string. |
|
278 | - * |
|
279 | - * @param Mailcode_StringContainer|string $subject |
|
280 | - * @return Mailcode_Parser_Safeguard_Formatting |
|
281 | - */ |
|
275 | + /** |
|
276 | + * Creates a formatting handler, which can be used to specify |
|
277 | + * which formattings to use for the commands in the subject string. |
|
278 | + * |
|
279 | + * @param Mailcode_StringContainer|string $subject |
|
280 | + * @return Mailcode_Parser_Safeguard_Formatting |
|
281 | + */ |
|
282 | 282 | public function createFormatting($subject) : Mailcode_Parser_Safeguard_Formatting |
283 | 283 | { |
284 | 284 | if(is_string($subject)) |
@@ -289,12 +289,12 @@ discard block |
||
289 | 289 | return new Mailcode_Parser_Safeguard_Formatting($this, $subject); |
290 | 290 | } |
291 | 291 | |
292 | - /** |
|
293 | - * Retrieves all placeholders that have to be added to |
|
294 | - * the subject text. |
|
295 | - * |
|
296 | - * @return \Mailcode\Mailcode_Parser_Safeguard_Placeholder[] |
|
297 | - */ |
|
292 | + /** |
|
293 | + * Retrieves all placeholders that have to be added to |
|
294 | + * the subject text. |
|
295 | + * |
|
296 | + * @return \Mailcode\Mailcode_Parser_Safeguard_Placeholder[] |
|
297 | + */ |
|
298 | 298 | public function getPlaceholders() |
299 | 299 | { |
300 | 300 | if(isset($this->placeholders)) |
@@ -370,16 +370,16 @@ discard block |
||
370 | 370 | return $string; |
371 | 371 | } |
372 | 372 | |
373 | - /** |
|
374 | - * Makes the string whole again after transforming or filtering it, |
|
375 | - * by replacing the command placeholders with the original commands. |
|
376 | - * |
|
377 | - * @param string $string |
|
378 | - * @return string |
|
379 | - * @throws Mailcode_Exception |
|
380 | - * |
|
381 | - * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
382 | - */ |
|
373 | + /** |
|
374 | + * Makes the string whole again after transforming or filtering it, |
|
375 | + * by replacing the command placeholders with the original commands. |
|
376 | + * |
|
377 | + * @param string $string |
|
378 | + * @return string |
|
379 | + * @throws Mailcode_Exception |
|
380 | + * |
|
381 | + * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
382 | + */ |
|
383 | 383 | public function makeWhole(string $string) : string |
384 | 384 | { |
385 | 385 | return $this->restore( |
@@ -389,15 +389,15 @@ discard block |
||
389 | 389 | ); |
390 | 390 | } |
391 | 391 | |
392 | - /** |
|
393 | - * Like `makeWhole()`, but ignores missing command placeholders. |
|
394 | - * |
|
395 | - * @param string $string |
|
396 | - * @return string |
|
397 | - * @throws Mailcode_Exception |
|
398 | - * |
|
399 | - * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
400 | - */ |
|
392 | + /** |
|
393 | + * Like `makeWhole()`, but ignores missing command placeholders. |
|
394 | + * |
|
395 | + * @param string $string |
|
396 | + * @return string |
|
397 | + * @throws Mailcode_Exception |
|
398 | + * |
|
399 | + * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
400 | + */ |
|
401 | 401 | public function makeWholePartial(string $string) : string |
402 | 402 | { |
403 | 403 | return $this->restore( |
@@ -407,19 +407,19 @@ discard block |
||
407 | 407 | ); |
408 | 408 | } |
409 | 409 | |
410 | - /** |
|
411 | - * Like `makeWhole()`, but replaces the commands with a syntax |
|
412 | - * highlighted version, meant for human readable texts only. |
|
413 | - * |
|
414 | - * Note: the commands lose their functionality (They cannot be |
|
415 | - * parsed from that string again). |
|
416 | - * |
|
417 | - * @param string $string |
|
418 | - * @return string |
|
419 | - * @throws Mailcode_Exception |
|
420 | - * |
|
421 | - * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
422 | - */ |
|
410 | + /** |
|
411 | + * Like `makeWhole()`, but replaces the commands with a syntax |
|
412 | + * highlighted version, meant for human readable texts only. |
|
413 | + * |
|
414 | + * Note: the commands lose their functionality (They cannot be |
|
415 | + * parsed from that string again). |
|
416 | + * |
|
417 | + * @param string $string |
|
418 | + * @return string |
|
419 | + * @throws Mailcode_Exception |
|
420 | + * |
|
421 | + * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
422 | + */ |
|
423 | 423 | public function makeHighlighted(string $string) : string |
424 | 424 | { |
425 | 425 | return $this->restore( |
@@ -429,15 +429,15 @@ discard block |
||
429 | 429 | ); |
430 | 430 | } |
431 | 431 | |
432 | - /** |
|
433 | - * Like `makeHighlighted()`, but ignores missing command placeholders. |
|
434 | - * |
|
435 | - * @param string $string |
|
436 | - * @return string |
|
437 | - * @throws Mailcode_Exception |
|
438 | - * |
|
439 | - * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
440 | - */ |
|
432 | + /** |
|
433 | + * Like `makeHighlighted()`, but ignores missing command placeholders. |
|
434 | + * |
|
435 | + * @param string $string |
|
436 | + * @return string |
|
437 | + * @throws Mailcode_Exception |
|
438 | + * |
|
439 | + * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
440 | + */ |
|
441 | 441 | public function makeHighlightedPartial(string $string) : string |
442 | 442 | { |
443 | 443 | return $this->restore( |
@@ -447,11 +447,11 @@ discard block |
||
447 | 447 | ); |
448 | 448 | } |
449 | 449 | |
450 | - /** |
|
451 | - * Retrieves the commands collection contained in the string. |
|
452 | - * |
|
453 | - * @return Mailcode_Collection |
|
454 | - */ |
|
450 | + /** |
|
451 | + * Retrieves the commands collection contained in the string. |
|
452 | + * |
|
453 | + * @return Mailcode_Collection |
|
454 | + */ |
|
455 | 455 | public function getCollection() : Mailcode_Collection |
456 | 456 | { |
457 | 457 | if(isset($this->collection)) |
@@ -469,11 +469,11 @@ discard block |
||
469 | 469 | return $this->getCollection()->isValid(); |
470 | 470 | } |
471 | 471 | |
472 | - /** |
|
473 | - * @throws Mailcode_Exception |
|
474 | - * |
|
475 | - * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
476 | - */ |
|
472 | + /** |
|
473 | + * @throws Mailcode_Exception |
|
474 | + * |
|
475 | + * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
476 | + */ |
|
477 | 477 | protected function requireValidCollection() : void |
478 | 478 | { |
479 | 479 | if($this->getCollection()->isValid()) |
@@ -492,11 +492,11 @@ discard block |
||
492 | 492 | ); |
493 | 493 | } |
494 | 494 | |
495 | - /** |
|
496 | - * Retrieves a list of all placeholder IDs used in the text. |
|
497 | - * |
|
498 | - * @return string[] |
|
499 | - */ |
|
495 | + /** |
|
496 | + * Retrieves a list of all placeholder IDs used in the text. |
|
497 | + * |
|
498 | + * @return string[] |
|
499 | + */ |
|
500 | 500 | public function getPlaceholderStrings() : array |
501 | 501 | { |
502 | 502 | if(is_array($this->placeholderStrings)) |
@@ -523,13 +523,13 @@ discard block |
||
523 | 523 | return in_array($subject, $ids); |
524 | 524 | } |
525 | 525 | |
526 | - /** |
|
527 | - * Retrieves a placeholder instance by its ID. |
|
528 | - * |
|
529 | - * @param int $id |
|
530 | - * @throws Mailcode_Exception If the placeholder was not found. |
|
531 | - * @return Mailcode_Parser_Safeguard_Placeholder |
|
532 | - */ |
|
526 | + /** |
|
527 | + * Retrieves a placeholder instance by its ID. |
|
528 | + * |
|
529 | + * @param int $id |
|
530 | + * @throws Mailcode_Exception If the placeholder was not found. |
|
531 | + * @return Mailcode_Parser_Safeguard_Placeholder |
|
532 | + */ |
|
533 | 533 | public function getPlaceholderByID(int $id) : Mailcode_Parser_Safeguard_Placeholder |
534 | 534 | { |
535 | 535 | $placeholders = $this->getPlaceholders(); |
@@ -552,13 +552,13 @@ discard block |
||
552 | 552 | ); |
553 | 553 | } |
554 | 554 | |
555 | - /** |
|
556 | - * Retrieves a placeholder instance by its replacement text. |
|
557 | - * |
|
558 | - * @param string $string |
|
559 | - * @throws Mailcode_Exception |
|
560 | - * @return Mailcode_Parser_Safeguard_Placeholder |
|
561 | - */ |
|
555 | + /** |
|
556 | + * Retrieves a placeholder instance by its replacement text. |
|
557 | + * |
|
558 | + * @param string $string |
|
559 | + * @throws Mailcode_Exception |
|
560 | + * @return Mailcode_Parser_Safeguard_Placeholder |
|
561 | + */ |
|
562 | 562 | public function getPlaceholderByString(string $string) : Mailcode_Parser_Safeguard_Placeholder |
563 | 563 | { |
564 | 564 | $placeholders = $this->getPlaceholders(); |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | */ |
124 | 124 | public function setDelimiter(string $delimiter) : Mailcode_Parser_Safeguard |
125 | 125 | { |
126 | - if(empty($delimiter)) |
|
126 | + if (empty($delimiter)) |
|
127 | 127 | { |
128 | 128 | throw new Mailcode_Exception( |
129 | 129 | 'Empty delimiter', |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | $placeholders = $this->getPlaceholders(); |
174 | 174 | $string = $this->originalString; |
175 | 175 | |
176 | - foreach($placeholders as $placeholder) |
|
176 | + foreach ($placeholders as $placeholder) |
|
177 | 177 | { |
178 | 178 | $string = $this->makePlaceholderSafe($string, $placeholder); |
179 | 179 | } |
@@ -203,14 +203,14 @@ discard block |
||
203 | 203 | $placeholders = $this->getPlaceholders(); |
204 | 204 | $total = count($placeholders); |
205 | 205 | |
206 | - for($i=0; $i < $total; $i++) |
|
206 | + for ($i = 0; $i < $total; $i++) |
|
207 | 207 | { |
208 | 208 | $placeholder = $placeholders[$i]; |
209 | 209 | $command = $placeholder->getCommand(); |
210 | 210 | |
211 | - if($command instanceof Mailcode_Interfaces_Commands_ProtectedContent) |
|
211 | + if ($command instanceof Mailcode_Interfaces_Commands_ProtectedContent) |
|
212 | 212 | { |
213 | - $string = $command->protectContent($string, $placeholder, $placeholders[$i+1]); |
|
213 | + $string = $command->protectContent($string, $placeholder, $placeholders[$i + 1]); |
|
214 | 214 | } |
215 | 215 | } |
216 | 216 | |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | { |
222 | 222 | $pos = mb_strpos($string, $placeholder->getOriginalText()); |
223 | 223 | |
224 | - if($pos === false) |
|
224 | + if ($pos === false) |
|
225 | 225 | { |
226 | 226 | throw new Mailcode_Exception( |
227 | 227 | 'Placeholder original text not found', |
@@ -253,18 +253,18 @@ discard block |
||
253 | 253 | |
254 | 254 | $placeholders = $this->getPlaceholders(); |
255 | 255 | |
256 | - foreach($urls as $url) |
|
256 | + foreach ($urls as $url) |
|
257 | 257 | { |
258 | - foreach($placeholders as $placeholder) |
|
258 | + foreach ($placeholders as $placeholder) |
|
259 | 259 | { |
260 | 260 | $command = $placeholder->getCommand(); |
261 | 261 | |
262 | - if(!$command->supportsURLEncoding()) |
|
262 | + if (!$command->supportsURLEncoding()) |
|
263 | 263 | { |
264 | 264 | continue; |
265 | 265 | } |
266 | 266 | |
267 | - if(strstr($url, $placeholder->getReplacementText())) |
|
267 | + if (strstr($url, $placeholder->getReplacementText())) |
|
268 | 268 | { |
269 | 269 | $command->setURLEncoding(true); |
270 | 270 | } |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | */ |
282 | 282 | public function createFormatting($subject) : Mailcode_Parser_Safeguard_Formatting |
283 | 283 | { |
284 | - if(is_string($subject)) |
|
284 | + if (is_string($subject)) |
|
285 | 285 | { |
286 | 286 | $subject = Mailcode::create()->createString($subject); |
287 | 287 | } |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | */ |
298 | 298 | public function getPlaceholders() |
299 | 299 | { |
300 | - if(isset($this->placeholders)) |
|
300 | + if (isset($this->placeholders)) |
|
301 | 301 | { |
302 | 302 | return $this->placeholders; |
303 | 303 | } |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | |
307 | 307 | $cmds = $this->getCollection()->getCommands(); |
308 | 308 | |
309 | - foreach($cmds as $command) |
|
309 | + foreach ($cmds as $command) |
|
310 | 310 | { |
311 | 311 | self::$counter++; |
312 | 312 | |
@@ -327,21 +327,21 @@ discard block |
||
327 | 327 | * @return string |
328 | 328 | * @throws Mailcode_Exception |
329 | 329 | */ |
330 | - protected function restore(string $string, bool $partial=false, bool $highlighted=false) : string |
|
330 | + protected function restore(string $string, bool $partial = false, bool $highlighted = false) : string |
|
331 | 331 | { |
332 | - if(!$partial) |
|
332 | + if (!$partial) |
|
333 | 333 | { |
334 | 334 | $this->requireValidCollection(); |
335 | 335 | } |
336 | 336 | |
337 | 337 | $formatting = $this->createFormatting($string); |
338 | 338 | |
339 | - if($partial) |
|
339 | + if ($partial) |
|
340 | 340 | { |
341 | 341 | $formatting->makePartial(); |
342 | 342 | } |
343 | 343 | |
344 | - if($highlighted) |
|
344 | + if ($highlighted) |
|
345 | 345 | { |
346 | 346 | $formatting->replaceWithHTMLHighlighting(); |
347 | 347 | } |
@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | { |
362 | 362 | $command = $placeholder->getCommand(); |
363 | 363 | |
364 | - if($command instanceof Mailcode_Interfaces_Commands_ProtectedContent) |
|
364 | + if ($command instanceof Mailcode_Interfaces_Commands_ProtectedContent) |
|
365 | 365 | { |
366 | 366 | $string = $command->restoreContent($string); |
367 | 367 | } |
@@ -454,7 +454,7 @@ discard block |
||
454 | 454 | */ |
455 | 455 | public function getCollection() : Mailcode_Collection |
456 | 456 | { |
457 | - if(isset($this->collection)) |
|
457 | + if (isset($this->collection)) |
|
458 | 458 | { |
459 | 459 | return $this->collection; |
460 | 460 | } |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | */ |
477 | 477 | protected function requireValidCollection() : void |
478 | 478 | { |
479 | - if($this->getCollection()->isValid()) |
|
479 | + if ($this->getCollection()->isValid()) |
|
480 | 480 | { |
481 | 481 | return; |
482 | 482 | } |
@@ -499,7 +499,7 @@ discard block |
||
499 | 499 | */ |
500 | 500 | public function getPlaceholderStrings() : array |
501 | 501 | { |
502 | - if(is_array($this->placeholderStrings)) |
|
502 | + if (is_array($this->placeholderStrings)) |
|
503 | 503 | { |
504 | 504 | return $this->placeholderStrings; |
505 | 505 | } |
@@ -508,7 +508,7 @@ discard block |
||
508 | 508 | |
509 | 509 | $this->placeholderStrings = array(); |
510 | 510 | |
511 | - foreach($placeholders as $placeholder) |
|
511 | + foreach ($placeholders as $placeholder) |
|
512 | 512 | { |
513 | 513 | $this->placeholderStrings[] = $placeholder->getReplacementText(); |
514 | 514 | } |
@@ -534,9 +534,9 @@ discard block |
||
534 | 534 | { |
535 | 535 | $placeholders = $this->getPlaceholders(); |
536 | 536 | |
537 | - foreach($placeholders as $placeholder) |
|
537 | + foreach ($placeholders as $placeholder) |
|
538 | 538 | { |
539 | - if($placeholder->getID() === $id) |
|
539 | + if ($placeholder->getID() === $id) |
|
540 | 540 | { |
541 | 541 | return $placeholder; |
542 | 542 | } |
@@ -563,9 +563,9 @@ discard block |
||
563 | 563 | { |
564 | 564 | $placeholders = $this->getPlaceholders(); |
565 | 565 | |
566 | - foreach($placeholders as $placeholder) |
|
566 | + foreach ($placeholders as $placeholder) |
|
567 | 567 | { |
568 | - if($placeholder->getReplacementText() === $string) |
|
568 | + if ($placeholder->getReplacementText() === $string) |
|
569 | 569 | { |
570 | 570 | return $placeholder; |
571 | 571 | } |