Skip to content

ValidatorSpec

A fluent handle onto a single, already-registered Validator instance.

Every setter here is a thin wrapper over Validator::setParameter() — safe to call any time before ValidationManager::execute() actually validates, since parameters are read lazily by validate(). There is no separate “build”/“commit” step: ValidatorBuilder addChild()s the validator immediately when a spec is created, so a caller who never chains anything still gets a correctly registered (if minimally configured) validator.

final class ValidatorSpec

Since1.0.0
SourceValidator/Compiler/Runtime/ValidatorSpec.php

public function __construct(Validator $validator): mixed

ParameterTypeDescription
$validatorValidator

Returns mixed

MethodDescription
breakOnFirst(bool $break = true): ValidatorSpecSets the break parameter, deciding whether the operator stops running children once one has settled the outcome.
caseSensitive(bool $caseSensitive = true): ValidatorSpecSets the case parameter, deciding whether the allowlist comparison respects letter case.
castTo(string $type): ValidatorSpecSets the cast_to parameter, the type the accepted value is converted to before it is exported.
error(string $message, ?string $for = null): ValidatorSpecSets an error message on the validator.
export(string $to): ValidatorSpecSets the export parameter, naming the request-data key the validated value is written back to.
[`max(intfloat $max): ValidatorSpec`](#max)
maxLength(int $max): ValidatorSpecSets the max parameter, the longest accepted string length.
[`min(intfloat $min): ValidatorSpec`](#min)
minLength(int $min): ValidatorSpecSets the min parameter, the shortest accepted string length.
required(bool $required = true): ValidatorSpecSets the required parameter, deciding whether a missing argument is itself an error.
severity(string $severity): ValidatorSpecSets the severity parameter, which decides how far a failure of this validator escalates the request’s overall validation result.
shouldMatch(bool $shouldMatch = true): ValidatorSpecSets the match parameter; false inverts the regex test, so the value passes only when the pattern does not match.
skipErrors(bool $skip = true): ValidatorSpecSets the skip_errors parameter, deciding whether the errors reported by child validators are discarded in favour of the operator’s own message.
strict(bool $strict = true): ValidatorSpecSets the strict parameter, deciding whether the allowlist comparison also requires a matching type.
translationDomain(string $domain): ValidatorSpecSets the translation_domain parameter used when this validator’s error messages are translated.
trim(bool $trim = true): ValidatorSpecSets the trim parameter, deciding whether surrounding whitespace is stripped before the value is checked.
type(string $type): ValidatorSpecSets the type parameter, the numeric type the value must conform to.
utf8(bool $utf8 = true): ValidatorSpecSets the utf8 parameter, deciding whether lengths are counted in UTF-8 characters rather than bytes.
validator(): ValidatorReturns the live Validator instance, for anything the setters below do not cover.

public function breakOnFirst(bool $break = true): ValidatorSpec

Sets the break parameter, deciding whether the operator stops running children once one has settled the outcome.

ParameterTypeDescription
$breakbool

Returns ValidatorSpec

public function caseSensitive(bool $caseSensitive = true): ValidatorSpec

Sets the case parameter, deciding whether the allowlist comparison respects letter case.

ParameterTypeDescription
$caseSensitivebool

Returns ValidatorSpec

public function castTo(string $type): ValidatorSpec

Sets the cast_to parameter, the type the accepted value is converted to before it is exported.

ParameterTypeDescription
$typestring

Returns ValidatorSpec

public function error(string $message, ?string $for = null): ValidatorSpec

Sets an error message on the validator.

$for names the specific failure the message belongs to; omitting it (or passing null) registers the message under the empty key, which is the validator’s default message for any failure without its own text.

ParameterTypeDescription
$messagestring
$for?``string

Returns ValidatorSpec

public function export(string $to): ValidatorSpec

Sets the export parameter, naming the request-data key the validated value is written back to.

ParameterTypeDescription
$tostring

Returns ValidatorSpec

public function max(int|float $max): ValidatorSpec

Sets the max parameter, the largest accepted numeric value.

ParameterTypeDescription
$max`int““float`

Returns ValidatorSpec

public function maxLength(int $max): ValidatorSpec

Sets the max parameter, the longest accepted string length.

ParameterTypeDescription
$maxint

Returns ValidatorSpec

public function min(int|float $min): ValidatorSpec

Sets the min parameter, the smallest accepted numeric value.

ParameterTypeDescription
$min`int““float`

Returns ValidatorSpec

public function minLength(int $min): ValidatorSpec

Sets the min parameter, the shortest accepted string length.

ParameterTypeDescription
$minint

Returns ValidatorSpec

public function required(bool $required = true): ValidatorSpec

Sets the required parameter, deciding whether a missing argument is itself an error.

ParameterTypeDescription
$requiredbool

Returns ValidatorSpec

public function severity(string $severity): ValidatorSpec

Sets the severity parameter, which decides how far a failure of this validator escalates the request’s overall validation result.

ParameterTypeDescription
$severitystring

Returns ValidatorSpec

public function shouldMatch(bool $shouldMatch = true): ValidatorSpec

Sets the match parameter; false inverts the regex test, so the value passes only when the pattern does not match.

ParameterTypeDescription
$shouldMatchbool

Returns ValidatorSpec

public function skipErrors(bool $skip = true): ValidatorSpec

Sets the skip_errors parameter, deciding whether the errors reported by child validators are discarded in favour of the operator’s own message.

ParameterTypeDescription
$skipbool

Returns ValidatorSpec

public function strict(bool $strict = true): ValidatorSpec

Sets the strict parameter, deciding whether the allowlist comparison also requires a matching type.

ParameterTypeDescription
$strictbool

Returns ValidatorSpec

public function translationDomain(string $domain): ValidatorSpec

Sets the translation_domain parameter used when this validator’s error messages are translated.

ParameterTypeDescription
$domainstring

Returns ValidatorSpec

public function trim(bool $trim = true): ValidatorSpec

Sets the trim parameter, deciding whether surrounding whitespace is stripped before the value is checked.

ParameterTypeDescription
$trimbool

Returns ValidatorSpec

public function type(string $type): ValidatorSpec

Sets the type parameter, the numeric type the value must conform to.

ParameterTypeDescription
$typestring

Returns ValidatorSpec

public function utf8(bool $utf8 = true): ValidatorSpec

Sets the utf8 parameter, deciding whether lengths are counted in UTF-8 characters rather than bytes.

ParameterTypeDescription
$utf8bool

Returns ValidatorSpec

public function validator(): Validator

Returns the live Validator instance, for anything the setters below do not cover.

Returns Validator