@@ -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(); |