PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

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