PHP
6 days ago
LICENSE.md
6 days ago
README.md
6 days ago
class-xmlattributetoken.php
6 days ago
class-xmldecoder.php
6 days ago
class-xmlelement.php
6 days ago
class-xmlnativecursorprocessor.php
6 days ago
class-xmlprocessor.php
6 days ago
class-xmlunsupportedexception.php
6 days ago
composer.json
6 days ago
class-xmlunsupportedexception.php
99 lines
| 1 | <?php |
| 2 | /** |
| 3 | * XML API: XMLUnsupportedException class |
| 4 | * |
| 5 | * @package WordPress\XML |
| 6 | */ |
| 7 | |
| 8 | namespace WordPress\XML; |
| 9 | |
| 10 | use Exception; |
| 11 | |
| 12 | /** |
| 13 | * Core class used by the XML processor during XML parsing |
| 14 | * for indicating that a given operation is unsupported. |
| 15 | * |
| 16 | * This class is designed for internal use by the XML processor. |
| 17 | * |
| 18 | * The XML API aims to operate in compliance with the XML 1.0 |
| 19 | * specification, but does not implement the full specification. |
| 20 | * In cases where it lacks support it should not cause breakage |
| 21 | * or unexpected behavior. In the cases where it recognizes that |
| 22 | * it cannot proceed, this class is used to abort from any |
| 23 | * operation and signify that the given XML cannot be processed. |
| 24 | * |
| 25 | * @since 6.4.0 |
| 26 | * @since 6.7.0 Gained contextual information for use in debugging parse failures. |
| 27 | * |
| 28 | * @access private |
| 29 | * |
| 30 | * @see XMLProcessor |
| 31 | */ |
| 32 | class XMLUnsupportedException extends Exception { |
| 33 | /** |
| 34 | * Name of the matched token when the exception was raised, |
| 35 | * if matched on a token. |
| 36 | * |
| 37 | * This does not imply that the token itself was unsupported, but it |
| 38 | * may have been the case that the token triggered part of the XML |
| 39 | * parsing that isn't supported, such as the adoption agency algorithm. |
| 40 | * |
| 41 | * @var string |
| 42 | */ |
| 43 | public $token_name; |
| 44 | |
| 45 | /** |
| 46 | * Number of bytes into the input XML document where the parser was |
| 47 | * parsing when the exception was raised. |
| 48 | * |
| 49 | * Use this to reconstruct context for the failure. |
| 50 | * |
| 51 | * @var int |
| 52 | */ |
| 53 | public $token_at; |
| 54 | |
| 55 | /** |
| 56 | * Full raw text of the matched token when the exception was raised, |
| 57 | * if matched on a token. |
| 58 | * |
| 59 | * Whereas the `$token_name` will be normalized, this contains the full |
| 60 | * raw text of the token, including original casing, duplicated attributes, |
| 61 | * and other syntactic variations that are normally abstracted in the XML API. |
| 62 | * |
| 63 | * @var string |
| 64 | */ |
| 65 | public $token; |
| 66 | |
| 67 | /** |
| 68 | * Stack of open elements when the exception was raised. |
| 69 | * |
| 70 | * Use this to trace the parsing circumstances which led to the exception. |
| 71 | * |
| 72 | * @var string[] |
| 73 | */ |
| 74 | public $stack_of_open_elements = array(); |
| 75 | |
| 76 | /** |
| 77 | * Constructor function. |
| 78 | * |
| 79 | * @param string $message Brief message explaining what is unsupported, the reason this exception was raised. |
| 80 | * @param string $token_name Normalized name of matched token when this exception was raised. |
| 81 | * @param int $token_at Number of bytes into source XML document where matched token starts. |
| 82 | * @param string $token Full raw text of matched token when this exception was raised. |
| 83 | * @param string[] $stack_of_open_elements Stack of open elements when this exception was raised. |
| 84 | */ |
| 85 | public function __construct( string $message, string $token_name, int $token_at, string $token, array $stack_of_open_elements ) { |
| 86 | parent::__construct( $message ); |
| 87 | |
| 88 | $this->token_name = $token_name; |
| 89 | $this->token_at = $token_at; |
| 90 | $this->token = $token; |
| 91 | |
| 92 | $this->stack_of_open_elements = $stack_of_open_elements; |
| 93 | } |
| 94 | |
| 95 | public function __toString() { |
| 96 | return $this->message . ' at ' . $this->token_at . ' in ' . $this->token; |
| 97 | } |
| 98 | } |
| 99 |