class ValidationRules (View source)

Properties

protected int $nodes

The number of schema fragments converted so far.

Methods

static array
for(Type|array $schema)

Get the validation rules for the properties of the given object schema.

array
properties(array $schema, string|null $prefix = null)

Get the rules for each property of an object schema, keyed under the given prefix.

array
rules(array $schema, string $attribute, bool $required, bool $nested = false)

Get the rules for one value and everything nested inside it.

array
presenceRules(array $schema, bool $required, bool $nested)

Get the rules that decide when the value must be present.

array
nestedRules(string|null $type, array $schema, string $attribute)

Get the rules for the items or properties nested inside the value.

array
typeRules(string|null $type, array $schema)

Get the rules a value of the given type must pass.

array
stringRules(array $schema)

Get the length, pattern, and format rules for a string schema.

array
formatRules(string|null $format)

Get the rules for the given string format.

array
numberRules(array $schema)

Get the bound and "multiple_of" rules for a numeric schema.

array
arrayRules(array $schema)

Get the rules an array value must pass.

array
objectRules(array $schema)

Get the rules an object value must pass.

array
enumRules(array $schema)

Get the rule that restricts the value to the schema's enumerated values.

anyOf(array $schemas)

Get the rule that passes when the value matches any of the given schemas.

array
bounds(array $schema, string $min, string $max)

Get the "min" and "max" rules for the given schema keywords.

array
types(array $schema)

Get the types the schema allows, other than "null".

bool
isNullable(array $schema)

Determine if the schema allows a null value.

string
parameters(array $values)

Join the given values into a quoted rule parameter list.

string
escapeDelimiter(string $pattern)

Escape each "/" in the pattern that is not already escaped by an odd number of backslashes.

Details

static array for(Type|array $schema)

Get the validation rules for the properties of the given object schema.

Parameters

Type|array $schema

Return Value

array

Exceptions

InvalidArgumentException

protected array properties(array $schema, string|null $prefix = null)

Get the rules for each property of an object schema, keyed under the given prefix.

Parameters

array $schema
string|null $prefix

Return Value

array

protected array rules(array $schema, string $attribute, bool $required, bool $nested = false)

Get the rules for one value and everything nested inside it.

Parameters

array $schema
string $attribute
bool $required
bool $nested

Return Value

array

protected array presenceRules(array $schema, bool $required, bool $nested)

Get the rules that decide when the value must be present.

Parameters

array $schema
bool $required
bool $nested

Return Value

array

protected array nestedRules(string|null $type, array $schema, string $attribute)

Get the rules for the items or properties nested inside the value.

Parameters

string|null $type
array $schema
string $attribute

Return Value

array

protected array typeRules(string|null $type, array $schema)

Get the rules a value of the given type must pass.

Parameters

string|null $type
array $schema

Return Value

array

protected array stringRules(array $schema)

Get the length, pattern, and format rules for a string schema.

Parameters

array $schema

Return Value

array

protected array formatRules(string|null $format)

Get the rules for the given string format.

Parameters

string|null $format

Return Value

array

protected array numberRules(array $schema)

Get the bound and "multiple_of" rules for a numeric schema.

Parameters

array $schema

Return Value

array

protected array arrayRules(array $schema)

Get the rules an array value must pass.

Parameters

array $schema

Return Value

array

protected array objectRules(array $schema)

Get the rules an object value must pass.

Parameters

array $schema

Return Value

array

protected array enumRules(array $schema)

Get the rule that restricts the value to the schema's enumerated values.

Parameters

array $schema

Return Value

array

protected MatchesAnyOf anyOf(array $schemas)

Get the rule that passes when the value matches any of the given schemas.

Parameters

array $schemas

Return Value

MatchesAnyOf

protected array bounds(array $schema, string $min, string $max)

Get the "min" and "max" rules for the given schema keywords.

Parameters

array $schema
string $min
string $max

Return Value

array

protected array types(array $schema)

Get the types the schema allows, other than "null".

Parameters

array $schema

Return Value

array

protected bool isNullable(array $schema)

Determine if the schema allows a null value.

Parameters

array $schema

Return Value

bool

protected string parameters(array $values)

Join the given values into a quoted rule parameter list.

Parameters

array $values

Return Value

string

protected string escapeDelimiter(string $pattern)

Escape each "/" in the pattern that is not already escaped by an odd number of backslashes.

Parameters

string $pattern

Return Value

string