/hphp/runtime/ext/xml/ext_xml.php

https://gitlab.com/Blueprint-Marketing/hhvm · PHP · 425 lines · 62 code · 24 blank · 339 comment · 0 complexity · f44e7a3597db53590c413de2018eb820 MD5 · raw file

  1. <?hh
  2. /**
  3. * xml_parser_create() creates a new XML parser and returns a resource handle
  4. * referencing it to be used by the other XML functions.
  5. *
  6. * @param string $encoding - The optional encoding specifies the character
  7. * encoding for the input/output in PHP 4. Starting from PHP 5, the input
  8. * encoding is automatically detected, so that the encoding parameter
  9. * specifies only the output encoding. In PHP 4, the default output encoding
  10. * is the same as the input charset. If empty string is passed, the parser
  11. * attempts to identify which encoding the document is encoded in by looking
  12. * at the heading 3 or 4 bytes. In PHP 5.0.0 and 5.0.1, the default output
  13. * charset is ISO-8859-1, while in PHP 5.0.2 and upper is UTF-8. The supported
  14. * encodings are ISO-8859-1, UTF-8 and US-ASCII.
  15. *
  16. * @return resource - Returns a resource handle for the new XML parser.
  17. *
  18. */
  19. <<__Native>>
  20. function xml_parser_create(?string $encoding = null): resource;
  21. /**
  22. * Frees the given XML parser.
  23. *
  24. * @param resource $parser - A reference to the XML parser to free.
  25. *
  26. * @return bool - This function returns FALSE if parser does not refer to a
  27. * valid parser, or else it frees the parser and returns TRUE.
  28. *
  29. */
  30. <<__Native>>
  31. function xml_parser_free(resource $parser): bool;
  32. /**
  33. * xml_parse() parses an XML document. The handlers for the configured events
  34. * are called as many times as necessary.
  35. *
  36. * @param resource $parser - A reference to the XML parser to use.
  37. * @param string $data - Chunk of data to parse. A document may be parsed
  38. * piece-wise by calling xml_parse() several times with new data, as long as
  39. * the is_final parameter is set and TRUE when the last data is parsed.
  40. * @param bool $is_final - If set and TRUE, data is the last piece of data
  41. * sent in this parse.
  42. *
  43. * @return int - Returns 1 on success or 0 on failure. For unsuccessful
  44. * parses, error information can be retrieved with xml_get_error_code(),
  45. * xml_error_string(), xml_get_current_line_number(),
  46. * xml_get_current_column_number() and xml_get_current_byte_index(). Entity
  47. * errors are reported at the end of the data thus only if is_final is set and
  48. * TRUE.
  49. *
  50. */
  51. <<__Native>>
  52. function xml_parse(resource $parser, string $data, bool $is_final = true): int;
  53. /**
  54. * This function parses an XML file into 2 parallel array structures, one
  55. * (index) containing pointers to the location of the appropriate values in
  56. * the values array. These last two parameters must be passed by reference.
  57. *
  58. * @return int - xml_parse_into_struct() returns 0 for failure and 1 for
  59. * success. This is not the same as FALSE and TRUE, be careful with operators
  60. * such as ===.
  61. *
  62. */
  63. <<__Native>>
  64. function xml_parse_into_struct(resource $parser,
  65. string $data,
  66. mixed &$values,
  67. mixed &$index = null): int;
  68. /**
  69. * xml_parser_create_ns() creates a new XML parser with XML namespace support
  70. * and returns a resource handle referencing it to be used by the other XML
  71. * functions.
  72. *
  73. * @param string $encoding - The optional encoding specifies the character
  74. * encoding for the input/output in PHP 4. Starting from PHP 5, the input
  75. * encoding is automatically detected, so that the encoding parameter
  76. * specifies only the output encoding. In PHP 4, the default output encoding
  77. * is the same as the input charset. In PHP 5.0.0 and 5.0.1, the default
  78. * output charset is ISO-8859-1, while in PHP 5.0.2 and upper is UTF-8. The
  79. * supported encodings are ISO-8859-1, UTF-8 and US-ASCII.
  80. * @param string $separator - With a namespace aware parser tag parameters
  81. * passed to the various handler functions will consist of namespace and tag
  82. * name separated by the string specified in separator.
  83. *
  84. * @return resource - Returns a resource handle for the new XML parser.
  85. *
  86. */
  87. <<__Native>>
  88. function xml_parser_create_ns(?string $encoding = null,
  89. ?string $separator = null): resource;
  90. /**
  91. * Gets an option value from an XML parser.
  92. *
  93. * @param resource $parser - A reference to the XML parser to get an option
  94. * from.
  95. * @param int $option - Which option to fetch. XML_OPTION_CASE_FOLDING and
  96. * XML_OPTION_TARGET_ENCODING are available. See xml_parser_set_option() for
  97. * their description.
  98. *
  99. * @return mixed - This function returns FALSE if parser does not refer to a
  100. * valid parser or if option isn't valid (generates also a E_WARNING). Else
  101. * the option's value is returned.
  102. *
  103. */
  104. <<__Native>>
  105. function xml_parser_get_option(resource $parser, int $option): mixed;
  106. /**
  107. * Sets an option in an XML parser.
  108. *
  109. * @param resource $parser - A reference to the XML parser to set an option
  110. * in.
  111. * @param int $option - Which option to set. See below. The following options
  112. * are available: XML parser options Option constant Data type Description
  113. * XML_OPTION_CASE_FOLDING integer Controls whether case-folding is enabled
  114. * for this XML parser. Enabled by default. XML_OPTION_SKIP_TAGSTART integer
  115. * Specify how many characters should be skipped in the beginning of a tag
  116. * name. XML_OPTION_SKIP_WHITE integer Whether to skip values consisting of
  117. * whitespace characters. XML_OPTION_TARGET_ENCODING string Sets which target
  118. * encoding to use in this XML parser.By default, it is set to the same as the
  119. * source encoding used by xml_parser_create(). Supported target encodings are
  120. * ISO-8859-1, US-ASCII and UTF-8.
  121. * @param mixed $value - The option's new value.
  122. *
  123. * @return bool - This function returns FALSE if parser does not refer to a
  124. * valid parser, or if the option could not be set. Else the option is set and
  125. * TRUE is returned.
  126. *
  127. */
  128. <<__Native>>
  129. function xml_parser_set_option(resource $parser,
  130. int $option,
  131. mixed $value): bool;
  132. /**
  133. * Sets the character data handler function for the XML parser parser.
  134. *
  135. * @param resource $parser
  136. * @param mixed $handler - handler is a string containing the name of a
  137. * function that must exist when xml_parse() is called for parser. The
  138. * function named by handler must accept two parameters: handler ( resource
  139. * $parser , string $data ) parser The first parameter, parser, is a reference
  140. * to the XML parser calling the handler.
  141. *
  142. * @return bool - Returns TRUE on success or FALSE on failure.
  143. *
  144. */
  145. <<__Native>>
  146. function xml_set_character_data_handler(resource $parser, mixed $handler): bool;
  147. /**
  148. * Sets the default handler function for the XML parser parser.
  149. *
  150. * @param resource $parser
  151. * @param mixed $handler - handler is a string containing the name of a
  152. * function that must exist when xml_parse() is called for parser. The
  153. * function named by handler must accept two parameters: handler ( resource
  154. * $parser , string $data ) parser The first parameter, parser, is a reference
  155. * to the XML parser calling the handler.
  156. *
  157. * @return bool - Returns TRUE on success or FALSE on failure.
  158. *
  159. */
  160. <<__Native>>
  161. function xml_set_default_handler(resource $parser, mixed $handler): bool;
  162. /**
  163. * Sets the element handler functions for the XML parser.
  164. * start_element_handler and end_element_handler are strings containing the
  165. * names of functions that must exist when xml_parse() is called for parser.
  166. *
  167. * @param resource $parser
  168. * @param mixed $start_element_handler - The function named by
  169. * start_element_handler must accept three parameters: start_element_handler (
  170. * resource $parser , string $name , array $attribs ) parser The first
  171. * parameter, parser, is a reference to the XML parser calling the handler.
  172. * @param mixed $end_element_handler - The second parameter, name, contains
  173. * the name of the element for which this handler is called.If case-folding is
  174. * in effect for this parser, the element name will be in uppercase letters.
  175. *
  176. * @return bool - Returns TRUE on success or FALSE on failure.
  177. *
  178. */
  179. <<__Native>>
  180. function xml_set_element_handler(resource $parser,
  181. mixed $start_element_handler,
  182. mixed $end_element_handler): bool;
  183. /**
  184. * Sets the processing instruction (PI) handler function for the XML parser
  185. * parser. A processing instruction has the following format: target data?>
  186. * You can put PHP code into such a tag, but be aware of one limitation: in an
  187. * XML PI, the PI end tag (?>) can not be quoted, so this character sequence
  188. * should not appear in the PHP code you embed with PIs in XML documents.If it
  189. * does, the rest of the PHP code, as well as the "real" PI end tag, will be
  190. * treated as character data.
  191. *
  192. * @param resource $parser
  193. * @param mixed $handler - handler is a string containing the name of a
  194. * function that must exist when xml_parse() is called for parser. The
  195. * function named by handler must accept three parameters: handler ( resource
  196. * $parser , string $target , string $data ) parser The first parameter,
  197. * parser, is a reference to the XML parser calling the handler.
  198. *
  199. * @return bool - Returns TRUE on success or FALSE on failure.
  200. *
  201. */
  202. <<__Native>>
  203. function xml_set_processing_instruction_handler(resource $parser,
  204. mixed $handler): bool;
  205. /**
  206. * Set a handler to be called when a namespace is declared. Namespace
  207. * declarations occur inside start tags. But the namespace declaration start
  208. * handler is called before the start tag handler for each namespace declared
  209. * in that start tag.
  210. *
  211. * @param resource $parser - A reference to the XML parser.
  212. * @param mixed $handler - handler is a string containing the name of a
  213. * function that must exist when xml_parse() is called for parser. The
  214. * function named by handler must accept four parameters, and should return an
  215. * integer value. If the value returned from the handler is FALSE (which it
  216. * will be if no value is returned), the XML parser will stop parsing and
  217. * xml_get_error_code() will return XML_ERROR_EXTERNAL_ENTITY_HANDLING.
  218. * handler ( resource $parser , string $user_data , string $prefix , string
  219. * $uri ) parser The first parameter, parser, is a reference to the XML parser
  220. * calling the handler.
  221. *
  222. * @return bool - Returns TRUE on success or FALSE on failure.
  223. *
  224. */
  225. <<__Native>>
  226. function xml_set_start_namespace_decl_handler(resource $parser,
  227. mixed $handler): bool;
  228. /**
  229. * Set a handler to be called when leaving the scope of a namespace
  230. * declaration. This will be called, for each namespace declaration, after the
  231. * handler for the end tag of the element in which the namespace was declared.
  232. *
  233. * @param resource $parser - A reference to the XML parser.
  234. * @param mixed $handler - handler is a string containing the name of a
  235. * function that must exist when xml_parse() is called for parser. The
  236. * function named by handler must accept three parameters, and should return
  237. * an integer value. If the value returned from the handler is FALSE (which it
  238. * will be if no value is returned), the XML parser will stop parsing and
  239. * xml_get_error_code() will return XML_ERROR_EXTERNAL_ENTITY_HANDLING.
  240. * handler ( resource $parser , string $user_data , string $prefix ) parser
  241. * The first parameter, parser, is a reference to the XML parser calling the
  242. * handler.
  243. *
  244. * @return bool - Returns TRUE on success or FALSE on failure.
  245. *
  246. */
  247. <<__Native>>
  248. function xml_set_end_namespace_decl_handler(resource $parser,
  249. mixed $handler): bool;
  250. /**
  251. * @param resource $parser
  252. * @param mixed $handler - handler is a string containing the name of a
  253. * function that must exist when xml_parse() is called for parser. The
  254. * function named by handler must accept six parameters: handler ( resource
  255. * $parser , string $entity_name , string $base , string $system_id , string
  256. * $public_id , string $notation_name ) parser The first parameter, parser, is
  257. * a reference to the XML parser calling the handler.
  258. *
  259. * @return bool - Returns TRUE on success or FALSE on failure.
  260. *
  261. */
  262. <<__Native>>
  263. function xml_set_unparsed_entity_decl_handler(resource $parser,
  264. mixed $handler): bool;
  265. /**
  266. * Sets the external entity reference handler function for the XML parser
  267. * parser.
  268. *
  269. * @param resource $parser
  270. * @param mixed $handler - handler is a string containing the name of a
  271. * function that must exist when xml_parse() is called for parser. The
  272. * function named by handler must accept five parameters, and should return an
  273. * integer value.If the value returned from the handler is FALSE (which it
  274. * will be if no value is returned), the XML parser will stop parsing and
  275. * xml_get_error_code() will return XML_ERROR_EXTERNAL_ENTITY_HANDLING.
  276. * handler ( resource $parser , string $open_entity_names , string $base ,
  277. * string $system_id , string $public_id ) parser The first parameter, parser,
  278. * is a reference to the XML parser calling the handler.
  279. *
  280. * @return bool - Returns TRUE on success or FALSE on failure.
  281. *
  282. */
  283. <<__Native>>
  284. function xml_set_external_entity_ref_handler(resource $parser,
  285. mixed $handler): bool;
  286. /**
  287. * @param resource $parser
  288. * @param mixed $handler - handler is a string containing the name of a
  289. * function that must exist when xml_parse() is called for parser. The
  290. * function named by handler must accept five parameters: handler ( resource
  291. * $parser , string $notation_name , string $base , string $system_id , string
  292. * $public_id ) parser The first parameter, parser, is a reference to the XML
  293. * parser calling the handler.
  294. *
  295. * @return bool - Returns TRUE on success or FALSE on failure.
  296. *
  297. */
  298. <<__Native>>
  299. function xml_set_notation_decl_handler(resource $parser, mixed $handler): bool;
  300. /**
  301. * This function allows to use parser inside object. All callback functions
  302. * could be set with xml_set_element_handler() etc and assumed to be methods
  303. * of object.
  304. *
  305. * @return bool - Returns TRUE on success or FALSE on failure.
  306. *
  307. */
  308. <<__Native>>
  309. function xml_set_object(resource $parser, mixed &$object): bool;
  310. /**
  311. * Gets the current byte index of the given XML parser.
  312. *
  313. * @param resource $parser - A reference to the XML parser to get byte index
  314. * from.
  315. *
  316. * @return int - This function returns FALSE if parser does not refer to a
  317. * valid parser, or else it returns which byte index the parser is currently
  318. * at in its data buffer (starting at 0).
  319. *
  320. */
  321. <<__Native>>
  322. function xml_get_current_byte_index(resource $parser): int;
  323. /**
  324. * Gets the current column number of the given XML parser.
  325. *
  326. * @param resource $parser - A reference to the XML parser to get column
  327. * number from.
  328. *
  329. * @return int - This function returns FALSE if parser does not refer to a
  330. * valid parser, or else it returns which column on the current line (as given
  331. * by xml_get_current_line_number()) the parser is currently at.
  332. *
  333. */
  334. <<__Native>>
  335. function xml_get_current_column_number(resource $parser): int;
  336. /**
  337. * Gets the current line number for the given XML parser.
  338. *
  339. * @param resource $parser - A reference to the XML parser to get line number
  340. * from.
  341. *
  342. * @return int - This function returns FALSE if parser does not refer to a
  343. * valid parser, or else it returns which line the parser is currently at in
  344. * its data buffer.
  345. *
  346. */
  347. <<__Native>>
  348. function xml_get_current_line_number(resource $parser): int;
  349. /**
  350. * Gets the XML parser error code.
  351. *
  352. * @param resource $parser - A reference to the XML parser to get error code
  353. * from.
  354. *
  355. * @return int - This function returns FALSE if parser does not refer to a
  356. * valid parser, or else it returns one of the error codes listed in the error
  357. * codes section.
  358. *
  359. */
  360. <<__Native>>
  361. function xml_get_error_code(resource $parser): int;
  362. /**
  363. * Gets the XML parser error string associated with the given code.
  364. *
  365. * @param int $code - An error code from xml_get_error_code().
  366. *
  367. * @return string - Returns a string with a textual description of the error
  368. * code, or FALSE if no description was found.
  369. *
  370. */
  371. <<__Native>>
  372. function xml_error_string(int $code): string;
  373. /**
  374. * This function decodes data, assumed to be UTF-8 encoded, to ISO-8859-1.
  375. *
  376. * @param string $data - An UTF-8 encoded string.
  377. *
  378. * @return string - Returns the ISO-8859-1 translation of data.
  379. *
  380. */
  381. <<__Native>>
  382. function utf8_decode(string $data): string;
  383. /**
  384. * This function encodes the string data to UTF-8, and returns the encoded
  385. * version. UTF-8 is a standard mechanism used by Unicode for encoding wide
  386. * character values into a byte stream. UTF-8 is transparent to plain ASCII
  387. * characters, is self-synchronized (meaning it is possible for a program to
  388. * figure out where in the bytestream characters start) and can be used with
  389. * normal string comparison functions for sorting and such. PHP encodes UTF-8
  390. * characters in up to four bytes, like this: UTF-8 encoding bytes bits
  391. * representation 1 7 0bbbbbbb 2 11 110bbbbb 10bbbbbb 3 16 1110bbbb 10bbbbbb
  392. * 10bbbbbb 4 21 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb Each b represents a bit
  393. * that can be used to store character data.
  394. *
  395. * @param string $data - An ISO-8859-1 string.
  396. *
  397. * @return string - Returns the UTF-8 translation of data.
  398. *
  399. */
  400. <<__Native>>
  401. function utf8_encode(string $data): string;