Validators
RustIn Appwrite#
Appwrite runs the Rust crate: the PHP extension serves the library and none of its PHP is left.
Rust 4,431 lines (2,851 code)· PHP 26 lines (10 code)split
| Part | Code | Comments | Blank | Total | Files |
|---|---|---|---|---|---|
| Rust source | 2,851 | 1,058 | 522 | 4,431 | 16 |
| PHP source | 10 | 12 | 4 | 26 | 1 |
Comments include doc comments. Each side counts its src/; the PHP side is what the package still has in PHP.
Served from Rust (32)
Utopia\Validator\AllOfUtopia\Validator\AnyOfUtopia\Validator\ArrayListUtopia\Validator\AssocUtopia\Validator\BooleanUtopia\Validator\ContainsUtopia\Validator\DomainUtopia\Validator\FloatValidatorUtopia\Validator\GlobstarUtopia\Validator\HexColorUtopia\Validator\HostUtopia\Validator\HostnameUtopia\Validator\IPUtopia\Validator\IdentifierUtopia\Validator\IntegerUtopia\Validator\JSONUtopia\Validator\JSON\ArrayValidatorUtopia\Validator\JSON\FCMUtopia\Validator\JSON\ObjectValidatorUtopia\Validator\LabelUtopia\Validator\MultipleUtopia\Validator\NoneOfUtopia\Validator\NullableUtopia\Validator\NumericUtopia\Validator\PhoneUtopia\Validator\PortUtopia\Validator\RangeUtopia\Validator\TextUtopia\Validator\URLUtopia\Validator\ValidatorUtopia\Validator\WhiteListUtopia\Validator\WildcardInstall#
cargo add utopia-validatorsOverview#
The checks of utopia-php/validators (packages/validators), as PHP runs them.
Each function is the body of a PHP validator's method over a value as PHP sees it
(Input): the same coercions (is_numeric(), $value + 0), the same comparisons and
the same messages. The validator classes themselves, and the state their constructors
keep, live in the PHP extension (crates/extension), which passes that state in.
| PHP | Rust |
|---|---|
Boolean::isValid() | boolean |
Integer::isValid(), getDescription(), getFormat() | Integer |
FloatValidator::isValid() | float |
Numeric::isValid() | numeric |
Range::isValid(), getDescription() | range, range_description |
Port::isValid() | port |
HexColor::isValid() | hex_color |
Text::isValid(), getDescription() | is_blank, text_length, text_description |
Identifier::isValid(), getDescription() | identifier, identifier_description |
WhiteList::__construct(), getDescription() | ascii_lower, white_list_description |
Contains::isValid(), getDescription() | lower, contains, contains_description |
Label::isValid(), getDescription() | label, LABEL_DESCRIPTION |
Hostname::isValid() | hostname, hostname_allowed |
Domain::isValid() | domain, explode_count |
IP::isValid() | ip |
URL::isValid(), getDescription(), isPrivateUseSchemeURI() | url_ascii, url, url_component, private_use_scheme, url_description |
Host::getDescription() | host_description |
Phone::isValid(), normalize() | phone, phone_normalize |
ArrayList::getDescription() | array_list_description |
JSON\ArrayValidator, JSON\ObjectValidator: getDescription(), hasValidLength() | json_array_description, json_object_description, json_length |
JSON\FCM::isValid() | FCM_REQUIRED, FCM_OPTIONAL, FCM_URL, non_empty, pem_private_key, https_scheme |
Globstar::matchGlobstar() | globstar_regex, exclusion, wildcard |
The composing validators (Nullable, ArrayList, AllOf, AnyOf, NoneOf, Multiple)
mostly ask the validators they wrap, which the extension does through the engine, as do the
PHP functions whose state is observable (json_decode(), json_encode(), preg_match(),
filter_var()).
A Rust caller that wants the value back in its type, not a bool, uses a [Validator]:
Boolean, Integer, Float, Range, Port, Text, Hostname and
WhiteList, which run the same checks.
Comparing a value with the PHP values a validator holds (the loose in_array() of Text's
allow list and of WhiteList, (string) of a pattern, Domain's restrictions) is left to
the PHP engine.
API#
What utopia_validators exports at its root.