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