Expand description
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()).
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.
Structs§
- Integer
- An integer of
bitsbits, signed orunsigned.
Enums§
- Filter
Value - A PHP value given to or returned by
filter_var(). - Input
- A PHP value as the validators look at it: scalars by value, strings as bytes, and
everything else (arrays, objects, resources) as
Input::Other, which no check here accepts as a number or a string. - Integer
Error - Why
new Integer()refuses its arguments;IntegerError::messageis theInvalidArgumentException’s. - IpType
- The IP versions
IPaccepts:IP::ALL,IP::V4orIP::V6. - Number
- A PHP number after
$value + 0. - UrlComponent
- A
PHP_URL_*selector forparse_url($url, $component).
Constants§
- ASSOC_
DESCRIPTION Assoc::getDescription().- DOMAIN_
DESCRIPTION Domain::getDescription().- FCM_
DESCRIPTION FCM::getDescription()before a check has failed.- FCM_
EMAIL_ ERROR - The error for a
client_emailfilter_var()refuses. - FCM_
KEY_ ERROR - The error for a
private_keythat is not PEM. - FCM_
OPTIONAL FCM::OPTIONAL_FIELDS.- FCM_
REQUIRED FCM::REQUIRED_FIELDS: each field and what it is for, in PHP’s order.- FCM_
TYPE_ ERROR - The error for a
typeother thanservice_account. - FCM_URL
FCM::URL_FIELDS.- GLOBSTAR_
DESCRIPTION Globstar::getDescription().- HOSTNAME_
DESCRIPTION Hostname::getDescription().- HOST_
DESCRIPTION_ PREFIX - What
Host::getDescription()puts beforeimplode(', ', $whitelist). - IP_
DESCRIPTION IP::getDescription().- JSON_
DESCRIPTION JSON::getDescription().- LABEL_
DESCRIPTION Label::getDescription():Label::MAX_LENGTHisLABEL_MAX_LENGTH.- LABEL_
MAX_ LENGTH Label::MAX_LENGTH: the longest DNS label.- LOOPBACK_
HOSTS - The hosts
URL’shttpsOrLoopbacklets plainhttpreach. - PEM_
BEGIN - The first line of a PEM private key.
- PEM_END
- The last line of a PEM private key.
- PHONE_
DESCRIPTION Phone::getDescription().- WHITE_
LIST_ DESCRIPTION - What
WhiteList::getDescription()puts aroundimplode(', ', $this->list).
Functions§
- array_
list_ description ArrayList::getDescription():itemis the wrapped validator’s description,Nonewhen it is''or'0'(which PHP leaves out).- ascii_
lower - PHP
strtolower(): ASCII only, whatever the locale (PHP 8.2 and later). - boolean
- A boolean; when
loose, also'true','false','1','0',1and0. - chars
- PHP
mb_strlen($value): each sequence that is not UTF-8 counts as one character. - contains
- PHP
str_contains($haystack, $needle): an empty needle is in every haystack. - contains_
description Contains::getDescription(), givenimplode(', ', $this->patterns), appended tomessage.- domain
Domain::isValid()’s format checks on a non-empty string:filter_var(FILTER_VALIDATE_DOMAIN)(withFILTER_FLAG_HOSTNAMEwhenhostnames) and no trailing.or-.- exclusion
- Whether a
Globstarpattern is an exclusion (!…). - explode_
count count(explode('.', $value, $limit)).- fcm_
optional_ error - The error for an optional field given but not a non-empty string.
- fcm_
required_ error - The error
FCM::isValid()records for a required field that is missing or blank. - fcm_
url_ error - The error for a URL field that is not an HTTPS URL.
- float
- An int or a float; when
loose, anythingis_numeric(). - globstar_
regex - The regular expression
Globstar::matchGlobstar()handspreg_match()forpattern, delimiters and anchors included (~^…$~). - hex_
color - A string of 3 or 6 hex digits, no
#. The pattern’s$also matches before a final newline, so one trailing"\n"is allowed. - host_
description Host::getDescription(), givenimplode(', ', $whitelist), appended todescription.- hostname
- The checks of
Hostname::isValid()before its allow list: not''or'0', at most 253 characters (mb_strlen()), no/and no:. - hostname_
allowed - Whether
valuematches an allow-list entryallowedthat is a string: equal to it,*, or a*.suffixwildcard thatvalueends with (the root itself is not matched). - https_
scheme - PHP
strtolower($scheme) === 'https'(ASCII lowercasing, as PHP 8 does). - identifier
preg_match('/^[A-Za-z_]\w*$/D', $value) === 1: an ASCII letter or_, then ASCII letters, digits and_(the pattern has no/u, so\wis ASCII), up to the very end.- identifier_
description Identifier::getDescription(), appended todescription.- ip
IP::isValid():filter_var($value, FILTER_VALIDATE_IP[, flag])is truthy.- ip_str
ipof a string: the filter on the string as it is (an address it accepts is never''or'0', so accepted is truthy).- is_
blank preg_match('/[^\p{Z}\p{Cf}\s]/u', $value) !== 1: the value holds only Unicode separators, format characters and whitespace (nothing at all included), or is not UTF-8, whichpreg_match()refuses.- json_
array_ description JSON\ArrayValidator::getDescription(), appended tomessage.- json_
length hasValidLength()of the JSON validators:encodedisNoneforfalse.- json_
object_ description JSON\ObjectValidator::getDescription(), appended tomessage.- label
Label::isValid()on a string: 1 to 63 bytes of lowercase ASCII letters, digits and hyphens, not starting or ending with a hyphen. (ctype_alnum()of what is left without the hyphens, so a label of hyphens only is refused.)- lower
- PHP
mb_strtolower($value, 'UTF-8'): full lower case, the final sigma rule, and?for each sequence that is not UTF-8. - non_
empty FCM::isNonEmptyString()of a string.- number_
le - PHP
$a <= $bon two numbers: exact between ints, as floats otherwise (NaN is never smaller or equal). - numeric
- Anything
is_numeric(): ints, floats (NANandINFincluded) and numeric strings. - pem_
private_ key str_starts_with($key, PEM_BEGIN) && str_ends_with(trim($key), PEM_END).- phone
Phone::isValid()’s pattern,/^\+[1-9]\d{6,14}$/.- phone_
normalize Phone::normalize():rawurldecode(), then a leading space (a+a query string decoded as a space) or no+at all before 7 to 15 digits becomes a+.- port
- A port from 1 to 65535, optionally after an IPv4 address or a bracketed IPv6 one and a
colon (
127.0.0.1:80,[::1]:443). An int is checked as its decimal string. - port_
host - An IPv4 address, or an IPv6 address in brackets.
- port_
number - Decimal digits without a leading zero, from 1 to 65535.
- preg_
quote - PHP
preg_quote($value, '~'). - private_
use_ scheme URL::isPrivateUseSchemeURI()on a string:Uri\Rfc3986\Uri::parse()succeeds, its (normalized) scheme contains a.and it has no host.- range
- A number from
mintomax, both included, offormat(seerange_number). - range_
description Value must be a valid range between 1 and 10, both bounds asnumber_format()prints them.- range_
number - The number
Range::isValid()compares with its bounds, for a value that passedis_numeric(): as'integer', an int (from+ 0, so a numeric string that makes one) or a float that already isINF/-INF(PHP checks$value === INFbefore+ 0, so a string such as'1e400'that overflows toINFis not one); as'double', any number as a float;Nonewhen the value is not one, and for any other format. - text_
description Text::getDescription(), givenimplode(', ', $this->allowList)when the list is not empty.- text_
length mb_strlen($value) >= $minand, for a$lengthother than 0,mb_strlen($value) <= $length.- trim
- PHP
trim($value): the default characters (" \t\n\r\0\x0B") from both ends. - url
- Whether
filter_var($value, FILTER_VALIDATE_URL)is notfalse. - url_
ascii URL::isValid()’s IRI step: each byte above 127 asrawurlencode()encodes it.- url_
component parse_url($value, $component)for a string component:Nonewhere PHP returnsfalse(a malformed URL),Some(None)fornull(no such component).- url_
description URL::getDescription(), givenimplode(', ', $allowedSchemes)when there are schemes.- url_str
urlof a string: the filter on the string as it is.- white_
list_ description WhiteList::getDescription(), givenimplode(', ', $this->list), appended tomessage.- wildcard
- Whether a
Globstarpattern holds a wildcard (*,?or[).