PageRenderTime 45ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/runtime/ext/fb/ext_fb.php

http://github.com/facebook/hiphop-php
PHP | 302 lines | 66 code | 26 blank | 210 comment | 0 complexity | 106146e03ef5c3c870cddc0ee651fb8b 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. // generated by idl-to-hni.php
  3. namespace {
  4. /** Serialize data into a compact format that can be unserialized by
  5. * fb_unserialize().
  6. *
  7. * WARNING: FB_SERIALIZE_HACK_ARRAYS_AND_KEYSETS mode has been added in March
  8. * 2020, and support for underlying serialization format may not yet be
  9. * available in all non-Hack implementations yet. Caution is adviced when using
  10. * FB_SERIALIZE_HACK_ARRAYS_AND_KEYSETS for serializing data, which may be
  11. * deserialized outside of Hack.
  12. *
  13. * @param mixed $thing - What to serialize. Note that objects are not
  14. * supported.
  15. * @param options bitmask of options: FB_SERIALIZE_HACK_ARRAYS,
  16. * FB_SERIALIZE_HACK_ARRAYS_AND_KEYSETS.
  17. * @return mixed - Serialized data.
  18. */
  19. <<__HipHopSpecific, __Native, __Rx>>
  20. function fb_serialize(mixed $thing, int $options = 0): mixed;
  21. /** Unserialize previously fb_serialize()-ed data.
  22. * @param mixed $thing - What to unserialize.
  23. * @param mixed $success - Whether it was successful or not.
  24. * @param options bitmask of options: FB_SERIALIZE_HACK_ARRAYS,
  25. * FB_SERIALIZE_HACK_ARRAYS_AND_KEYSETS.
  26. * @return mixed - Unserialized data.
  27. */
  28. <<__HipHopSpecific, __Native>>
  29. function fb_unserialize(mixed $thing,
  30. <<__OutOnly("KindOfBoolean")>>
  31. inout mixed $success,
  32. int $options = 0): mixed;
  33. /** Serialize data into a compact format that can be unserialized by
  34. * fb_compact_unserialize(). In general produces smaller output compared to
  35. * fb_serialize(). Largest savings are on arrays with sequential (or almost
  36. * sequential) indexes, i.e. simple arrays like array($a, $b, $c). NOTE:
  37. * unlike serialize(), does not preserve internal references, i.e. array(&$a,
  38. * &$a) will become array($a, $a).
  39. * @param mixed $thing - What to serialize. Note that objects are not
  40. * supported.
  41. * @return mixed - Serialized data.
  42. */
  43. <<__HipHopSpecific, __Native, __Rx>>
  44. function fb_compact_serialize(mixed $thing): mixed;
  45. /** Unserialize a previously fb_compact_serialize()-ed data.
  46. * @param mixed $thing - What to unserialize.
  47. * @param mixed $success - Whether it was successful or not.
  48. * @param mixed $errcode - One of those FB_UNSERIALIZE_ constants to describe
  49. * what the decoding error was, if it failed.
  50. * @return mixed - Unserialized data.
  51. */
  52. <<__HipHopSpecific, __Native>>
  53. function fb_compact_unserialize(mixed $thing,
  54. <<__OutOnly("KindOfBoolean")>>
  55. inout mixed $success,
  56. <<__OutOnly>>
  57. inout mixed $errcode): mixed;
  58. /** Invokes a user handler upon calling a function or a class method. If this
  59. * handler returns FALSE, code will continue with original function.
  60. * Otherwise, it will return what handler tells. The handler function looks
  61. * like "intercept_handler($name, $obj, $params, $data, &$done)", where $name
  62. * is original function's fully-qualified name ('Class::method'), $obj is $this
  63. * for an instance method call or null for static method call or function calls,
  64. * and $params are original call's parameters. $data is what's passed to
  65. * fb_intercept() and set $done to false to indicate function should continue its
  66. * execution with old function as if interception did not happen. By default $done
  67. * is true so it will return handler's return immediately without executing old
  68. * function's code. Note that built-in functions are not interceptable.
  69. * @param string $name - The function or class method name to intercept. Use
  70. * "class::method" for method name. If empty, all functions will be
  71. * intercepted by the specified handler and registered individual handlers
  72. * will be replaced. To make sure individual handlers not affected by such a
  73. * call, call fb_intercept() with individual names afterwards.
  74. * @param mixed $handler - Callback to handle the interception. Use null,
  75. * false or empty string to unregister a previously registered handler. If
  76. * name is empty, all previously registered handlers, including those that are
  77. * set by individual function names, will be removed.
  78. * @param mixed $data - Extra data to pass to the handler when intercepting
  79. * @return bool - TRUE if successful, FALSE otherwise
  80. */
  81. <<__HipHopSpecific, __Native>>
  82. function fb_intercept(string $name,
  83. mixed $handler,
  84. mixed $data = null): bool;
  85. /**
  86. * As a replacement for fb_intercept, invokes a user handler upon calling a
  87. * function or a class method. This handler is expected to have signature
  88. * similar to "intercept_handler($name, $obj, $params)" where each
  89. * argument is same as fb_intercept. This handler is expected to return a shape
  90. * where if the shape contains 'value' field, then this value is returned
  91. * as the result of the original function, if the shape contains 'callback'
  92. * field, then the callback is called as the result of the original function,
  93. * if the shape contains 'prepend_this' field, then 'this' or lsb class
  94. * is prepended as the first argument to the callback, if neither value nor
  95. * callback is given, then the original function is executed.
  96. * If the function does not return a shape, then a runtime exception is raised.
  97. * Signature of the callback and the original function are required to be the
  98. * same including the arity and parity of reified arguments, otherwise, the
  99. * regular error mechanism will raise an error/throw an exception accordingly.
  100. * Note that built-in functions are not interceptable.
  101. * @param string $name - The function or class method name to intercept. Use
  102. * "class::method" for method name. If empty, all functions will be
  103. * intercepted by the specified handler and registered individual handlers
  104. * will be replaced. To make sure individual handlers not affected by such a
  105. * call, call fb_intercept2() with individual names afterwards.
  106. * @param mixed $handler - Callback to handle the interception. Use null,
  107. * false or empty string to unregister a previously registered handler. If
  108. * name is empty, all previously registered handlers, including those that are
  109. * set by individual function names, will be removed.
  110. * @return bool - TRUE if successful, FALSE otherwise
  111. */
  112. <<__HipHopSpecific, __Native>>
  113. function fb_intercept2(string $name, mixed $handler): bool;
  114. /** Rename a function, so that a function can be called with the new name.
  115. * When writing unit tests, one may want to stub out a function. To do so,
  116. * call fb_rename_function('func_to_stub_out', 'somename') then
  117. * fb_rename_function('new_func_to_replace_with', 'func_to_stub_out'). This
  118. * way, when calling func_to_stub_out(), it will actually execute
  119. * new_func_to_replace_with().
  120. * @param string $orig_func_name - Which function to rename.
  121. * @param string $new_func_name - What is the new name.
  122. * @return bool - TRUE if successful, FALSE otherwise.
  123. */
  124. <<__HipHopSpecific, __Native("NoFCallBuiltin")>>
  125. function fb_rename_function(string $orig_func_name,
  126. string $new_func_name): bool;
  127. /** Sanitize a string to make sure it's legal UTF-8 by stripping off any
  128. * characters that are not properly encoded.
  129. * @param mixed $input - What string to sanitize.
  130. * @return bool - Sanitized string.
  131. */
  132. <<__HipHopSpecific, __Native, __Rx>>
  133. function fb_utf8ize(inout mixed $input): bool;
  134. /** Count the number of UTF-8 code points in string or byte count if it's not
  135. * valid UTF-8.
  136. * @param string $input - The string.
  137. * @return int - Returns the count of code points if valid UTF-8 else byte
  138. * count.
  139. */
  140. <<__HipHopSpecific, __Native, __IsFoldable, __Rx>>
  141. function fb_utf8_strlen_deprecated(string $input): int;
  142. /** Count the number of UTF-8 code points in string, substituting U+FFFD for
  143. * invalid sequences.
  144. * @param string $input - The string.
  145. * @return int - Returns the number of code points interpreting string as
  146. * UTF-8.
  147. */
  148. <<__HipHopSpecific, __Native, __IsFoldable, __Rx>>
  149. function fb_utf8_strlen(string $input): int;
  150. /** Cuts a portion of str specified by the start and length parameters.
  151. * @param string $str - The original string.
  152. * @param int $start - If start is non-negative, fb_utf8_substr() cuts the
  153. * portion out of str beginning at start'th character, counting from zero. If
  154. * start is negative, fb_utf8_substr() cuts out the portion beginning at the
  155. * position, start characters away from the end of str.
  156. * @param int $length - If length is given and is positive, the return value
  157. * will contain at most length characters of the portion that begins at start
  158. * (depending on the length of string). If negative length is passed,
  159. * fb_utf8_substr() cuts the portion out of str from the start'th character up
  160. * to the character that is length characters away from the end of the string.
  161. * In case start is also negative, the start position is calculated beforehand
  162. * according to the rule explained above.
  163. * @return string - Returns the portion of str specified by the start and
  164. * length parameters. If str is shorter than start characters long, the empty
  165. * string will be returned.
  166. */
  167. <<__HipHopSpecific, __Native, __IsFoldable, __Rx>>
  168. function fb_utf8_substr(string $str,
  169. int $start,
  170. int $length = PHP_INT_MAX): string;
  171. /** Returns code coverage data collected so far. Turn on code coverage by
  172. * Eval.RecordCodeCoverage or by using fb_enable_code_coverage and call this
  173. * function periodically to get results. Eval.CodeCoverageOutputFile allows
  174. * you to specify an output file to store results at end of a script run from
  175. * command line. Use this function in server mode to collect results instead.
  176. * @param bool $flush - Whether to clear data after this function call.
  177. * @return darray<string,mixed>|false
  178. */
  179. <<__HipHopSpecific, __Native>>
  180. function fb_get_code_coverage(bool $flush): mixed;
  181. /** Enables code coverage. The coverage information is cleared.
  182. */
  183. <<__HipHopSpecific, __Native("NoFCallBuiltin")>>
  184. function fb_enable_code_coverage(): void;
  185. /** Disables and returns code coverage. The coverage information is cleared.
  186. */
  187. <<__HipHopSpecific, __Native("NoFCallBuiltin")>>
  188. function fb_disable_code_coverage(): darray<string, mixed>;
  189. /** Toggles the compression status of HipHop output, if headers have already
  190. * been sent this may be ignored.
  191. * @param bool $new_value - The new value for the compression state.
  192. * @return bool - The old value.
  193. */
  194. <<__HipHopSpecific, __Native>>
  195. function fb_output_compression(bool $new_value): bool;
  196. /** Set a callback function that is called when php tries to exit.
  197. * @param mixed $function - The callback to invoke. An exception object will
  198. * be passed to the function
  199. */
  200. <<__HipHopSpecific, __Native>>
  201. function fb_set_exit_callback(mixed $function): void;
  202. /** Get stats on flushing the last data chunk from server.
  203. * @return int - Total number of bytes flushed since last flush
  204. */
  205. <<__HipHopSpecific, __Native>>
  206. function fb_get_last_flush_size(): int;
  207. /** Gathers the statistics of the file named by filename, like lstat(), except
  208. * uses cached information from an internal inotify-based mechanism that may
  209. * not be updated during the duration of a request.
  210. * @param string $filename - Path to a file or a symbolic link.
  211. * @return mixed - Same format as the normal php lstat() function.
  212. */
  213. <<__Native>>
  214. function fb_lazy_lstat(string $filename): mixed;
  215. /** Returns a canonicalized version of the input path that contains no symbolic
  216. * links, like realpath(), except uses cached information from an internal
  217. * inotify-based mechanism that may not be updated during the duration of a
  218. * request.
  219. * @param string $filename - Fake path to the file.
  220. * @return string - Real path of the file.
  221. */
  222. <<__Native>>
  223. function fb_lazy_realpath(string $filename): mixed;
  224. } // namespace
  225. namespace HH {
  226. /** Disables and returns code coverage that contains file to coverage frequency.
  227. * The coverage information is cleared.
  228. */
  229. <<__HipHopSpecific, __Native("NoFCallBuiltin")>>
  230. function disable_code_coverage_with_frequency(): darray<string, mixed>;
  231. /** Returns an int for the upper (first) 64 bits of an md5 hash of a string.
  232. * The MD5 hash, usually presented as a hex value, is taken as big endian, and
  233. * this int result is the signed counterpart to the unsigned upper 64 bits.
  234. *
  235. * This function and the _lower version are generally only intended for
  236. * legacy use cases in which an MD5 hash is used to compute a number
  237. * of 64 bits or less. These functions are faster and prettier than calling
  238. * unpack+substr+md5/raw or hexdec+substr+md5. Note that hexdec converts
  239. * to floating point (information loss) for some 64-bit unsigned values.
  240. *
  241. * The faster and quite effective xxhash64 is generally recommended for
  242. * non-crypto hashing needs when no backward compatibility is needed.
  243. */
  244. <<__Native, __IsFoldable, __Rx>>
  245. function non_crypto_md5_upper(string $str): int;
  246. /** Returns an int for the lower (last) 64 bits of an md5 hash of a string.
  247. * The MD5 hash, usually presented as a hex value, is taken as big endian, and
  248. * this int result is the signed counterpart to the unsigned lower 64 bits.
  249. *
  250. * This function and the _upper version are generally only intended for
  251. * legacy use cases in which an MD5 hash is used to compute a number
  252. * of 64 bits or less. These functions are faster and prettier than calling
  253. * unpack+substr+md5/raw or hexdec+substr+md5. Note that hexdec converts
  254. * to floating point (information loss) for some 64-bit unsigned values.
  255. *
  256. * The faster and quite effective xxhash64 is generally recommended for
  257. * non-crypto hashing needs when no backward compatibility is needed.
  258. */
  259. <<__Native, __IsFoldable, __Rx>>
  260. function non_crypto_md5_lower(string $str): int;
  261. /** Returns the overflow part of multiplying two ints, as if they were unsigned.
  262. * In other words, this returns the upper 64 bits of the full product of
  263. * (unsigned)$a and (unsigned)$b. (The lower 64 bits is just `$a * $b`
  264. * regardless of signed/unsigned).
  265. */
  266. <<__Native, __IsFoldable, __Rx>>
  267. function int_mul_overflow(int $a, int $b): int;
  268. /** Returns the overflow part of multiplying two ints plus another int, as if
  269. * they were all unsigned. Specifically, this returns the upper 64 bits of
  270. * full (unsigned)$a * (unsigned)$b + (unsigned)$bias. $bias can be used to
  271. * manipulate rounding of the result.
  272. */
  273. <<__Native, __IsFoldable, __Rx>>
  274. function int_mul_add_overflow(int $a, int $b, int $bias): int;
  275. type INCORRECT_TYPE<T> = T;
  276. } // HH namespace