Skip to main content

Crate php_std

Crate php_std 

Source
Expand description

PHP engine semantics in Rust.

Utopia crates must behave exactly like their PHP libraries, and much of that behaviour comes from the PHP engine rather than the library: type juggling, is_numeric, (string) casts, loose comparison, strtolower, mb_*, number_format, json_encode/json_decode, filter_var, parse_url. Each is reimplemented here once, and Utopia crates use these functions instead of their own approximations.

PHP values are Value (types): byte strings, ordered arrays with integer and string keys, stdClass, and crate-defined objects. The codecs (json, serialize, igbinary), comparisons and sort work on it. Older string-level helpers (value, string, [format], filter) take request-model serde_json::Values, decoded the way Utopia\Http\Request decodes bodies (objects are associative arrays, except empty objects, which stay stdClass; Value::from_json is the same mapping).

Re-exports§

pub use types::Array;
pub use types::ArrayKey;
pub use types::EngineError;
pub use types::Extension;
pub use types::Never;
pub use types::Str;
pub use types::Value;

Modules§

csv
CSV parsing: str_getcsv() and fgetcsv().
datetime
Date and time: date()/DateTime::format, DateTime parsing and timezones, strtotime, microtime.
encoding
Encodings: URL encoding, http_build_query, base64, hex, HTML entities and quoted-printable.
filter
filter_var(): the validation filters (FILTER_VALIDATE_INT, BOOL, FLOAT, REGEXP, URL, EMAIL, IP, MAC, DOMAIN), the sanitizing filters (FILTER_DEFAULT/FILTER_UNSAFE_RAW, FILTER_SANITIZE_*) and FILTER_CALLBACK, with their flags and options, ported from ext/filter (logical_filters.c, sanitizing_filters.c, callback_filter.c, filter.c) of PHP 8.5.
format
Number formatting and casts: sprintf, number_format, round/ceil, intval/floatval and the (int) / (float) casts, fmod, max/min of numbers.
glob
Shell glob matching: PHP’s fnmatch().
igbinary
igbinary_serialize and igbinary_unserialize, byte-identical to the igbinary extension (3.2, format version 2, igbinary.compact_strings=On) of the PHP image. Appwrite’s cache and queue payloads use it.
json
json_encode, json_decode, json_validate, json_last_error and json_last_error_msg, as PHP 8.5’s ext/json implements them.
mb
Multibyte (mbstring) functions on UTF-8.
net
Network helpers: inet_pton/inet_ntop.
number
How PHP prints floats.
path
Path functions.
pcre
PHP’s PCRE functions: preg_match, preg_match_all, preg_replace, preg_split and preg_quote, on PCRE2 10.44 with its JIT, the library and version PHP 8.5 bundles.
random
Random numbers: PHP’s Mersenne Twister, the engine behind mt_rand(), rand(), array_rand() and shuffle().
serialize
serialize, unserialize and var_export, in PHP 8.5’s formats.
sort
PHP’s array sorting and set functions: sort, ksort, array_unique, array_diff, array_intersect, in_array and array_search, with the SORT_* flags.
string
Byte-string functions of ext/standard/string.c and ext/ctype, plus crypt(), password_hash() / password_verify() and hash().
system
Process and host functions.
types
The PHP value model: Value, Str, Array, ArrayKey.
url
parse_url and the PHP 8.5 URI extension (Uri\Rfc3986\Uri).
value
PHP value semantics (type juggling) on top of serde_json::Value.
yaml
yaml_parse() (ext-yaml 2.3 over libyaml 0.2.5) with the default ini settings: timestamps, !!binary and !php/object stay strings.