| 1 |
<?php |
| 2 |
|
| 3 |
namespace WP_DEFENDER_VENDOR\Safe; |
| 4 |
|
| 5 |
use WP_DEFENDER_VENDOR\Safe\Exceptions\XmlException; |
| 6 |
|
| 7 |
/** |
| 8 |
* xml_parser_create_ns creates a new XML parser |
| 9 |
* with XML namespace support and returns a resource handle referencing |
| 10 |
* it to be used by the other XML functions. |
| 11 |
* |
| 12 |
* @param string|null $encoding The input encoding is automatically detected, so that the |
| 13 |
* encoding parameter specifies only the output |
| 14 |
* encoding. In PHP 5.0.0 and 5.0.1, the default output charset is |
| 15 |
* ISO-8859-1, while in PHP 5.0.2 and upper is UTF-8. The supported |
| 16 |
* encodings are ISO-8859-1, UTF-8 and |
| 17 |
* US-ASCII. |
| 18 |
* @param string $separator With a namespace aware parser tag parameters passed to the various |
| 19 |
* handler functions will consist of namespace and tag name separated by |
| 20 |
* the string specified in separator. |
| 21 |
* |
| 22 |
* @return resource Returns a resource handle for the new XML parser. |
| 23 |
* @throws XmlException |
| 24 |
* |
| 25 |
*/ |
| 26 |
function xml_parser_create_ns(?string $encoding = null, string $separator = ":") |
| 27 |
{ |
| 28 |
error_clear_last(); |
| 29 |
if ($separator !== ":") { |
| 30 |
$result = \xml_parser_create_ns($encoding, $separator); |
| 31 |
} elseif ($encoding !== null) { |
| 32 |
$result = \xml_parser_create_ns($encoding); |
| 33 |
} else { |
| 34 |
$result = \xml_parser_create_ns(); |
| 35 |
} |
| 36 |
if ($result === false) { |
| 37 |
throw XmlException::createFromPhpError(); |
| 38 |
} |
| 39 |
return $result; |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
/** |
| 44 |
* xml_parser_create creates a new XML parser |
| 45 |
* and returns a resource handle referencing it to be used by the |
| 46 |
* other XML functions. |
| 47 |
* |
| 48 |
* @param string|null $encoding The optional encoding specifies the character |
| 49 |
* encoding for the input/output in PHP 4. Starting from PHP 5, the input |
| 50 |
* encoding is automatically detected, so that the |
| 51 |
* encoding parameter specifies only the output |
| 52 |
* encoding. In PHP 4, the default output encoding is the same as the |
| 53 |
* input charset. If empty string is passed, the parser attempts to identify |
| 54 |
* which encoding the document is encoded in by looking at the heading 3 or |
| 55 |
* 4 bytes. In PHP 5.0.0 and 5.0.1, the default output charset is |
| 56 |
* ISO-8859-1, while in PHP 5.0.2 and upper is UTF-8. The supported |
| 57 |
* encodings are ISO-8859-1, UTF-8 and |
| 58 |
* US-ASCII. |
| 59 |
* |
| 60 |
* @return resource Returns a resource handle for the new XML parser. |
| 61 |
* @throws XmlException |
| 62 |
* |
| 63 |
*/ |
| 64 |
function xml_parser_create(?string $encoding = null) |
| 65 |
{ |
| 66 |
error_clear_last(); |
| 67 |
if ($encoding !== null) { |
| 68 |
$result = \xml_parser_create($encoding); |
| 69 |
} else { |
| 70 |
$result = \xml_parser_create(); |
| 71 |
} |
| 72 |
if ($result === false) { |
| 73 |
throw XmlException::createFromPhpError(); |
| 74 |
} |
| 75 |
return $result; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
/** |
| 80 |
* This function allows to use parser inside |
| 81 |
* object. All callback functions could be set with |
| 82 |
* xml_set_element_handler etc and assumed to be |
| 83 |
* methods of object. |
| 84 |
* |
| 85 |
* @param resource $parser A reference to the XML parser to use inside the object. |
| 86 |
* @param object $object The object where to use the XML parser. |
| 87 |
* @throws XmlException |
| 88 |
* |
| 89 |
*/ |
| 90 |
function xml_set_object($parser, object &$object): void |
| 91 |
{ |
| 92 |
error_clear_last(); |
| 93 |
$result = \xml_set_object($parser, $object); |
| 94 |
if ($result === false) { |
| 95 |
throw XmlException::createFromPhpError(); |
| 96 |
} |
| 97 |
} |
| 98 |
|