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()andfgetcsv(). - 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_*) andFILTER_CALLBACK, with their flags and options, ported fromext/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/floatvaland the(int)/(float)casts,fmod,max/minof numbers. - glob
- Shell glob matching: PHP’s
fnmatch(). - igbinary
igbinary_serializeandigbinary_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_errorandjson_last_error_msg, as PHP 8.5’sext/jsonimplements 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_splitandpreg_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()andshuffle(). - serialize
serialize,unserializeandvar_export, in PHP 8.5’s formats.- sort
- PHP’s array sorting and set functions:
sort,ksort,array_unique,array_diff,array_intersect,in_arrayandarray_search, with theSORT_*flags. - string
- Byte-string functions of
ext/standard/string.candext/ctype, pluscrypt(),password_hash()/password_verify()andhash(). - system
- Process and host functions.
- types
- The PHP value model:
Value,Str,Array,ArrayKey. - url
parse_urland 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,!!binaryand!php/objectstay strings.