Skip to content

ValidatorInterface

What a validator container asks of a validator: configure it, run it against a request, and read back what it named, decided and exported.

The Validator base class supplies all of it, along with ~40 protected helpers for writing one. This interface is the public contract a container and a test double need, so nothing has to depend on that base class to hold or drive a validator.

interface ValidatorInterface

Implemented byValidator
Since3.2.0
SourceValidator/ValidatorInterface.php
MethodDescription
execute(WebRequest $parameters): intRun this validator against $parameters.
[`getArguments(): array<intstring, mixed>`](#getarguments)
getBase(): mixedThe base path relative argument names resolve against.
getDependencyManager(): ?DependencyManagerThe dependency manager coordinating provides/depends between validators.
getMutatedRequest(): ?WebRequestThe request this validator produced, when it exported values, or null when it changed nothing.
getName(): ?stringThis validator’s declared name.
getParentContainer(): ?IValidatorContainerThe container holding this validator.
[`initialize(Context $context, array<string, mixed> $parameters = [], array<intstring, mixed> $arguments = [], array<int
setErrorMessage(string $index, string $message): voidOverride the message reported for one error index.
setParentContainer(IValidatorContainer $parent): mixedAttach this validator to its container.
shutdown(): mixedRelease anything held for the duration of one validation run.

abstract public function execute(WebRequest $parameters): int

Run this validator against $parameters.

ParameterTypeDescription
$parametersWebRequest

Returns int — The validation result code.

abstract public function getArguments(): array<int|string, mixed>

The argument names this validator targets.

Returns array``<``int``|``string``, ``mixed``>

abstract public function getBase(): mixed

The base path relative argument names resolve against.

Returns mixed

abstract public function getDependencyManager(): ?DependencyManager

The dependency manager coordinating provides/depends between validators.

Returns ?DependencyManager

abstract public function getMutatedRequest(): ?WebRequest

The request this validator produced, when it exported values, or null when it changed nothing.

Validators run against an immutable request, so an export is a new instance the caller has to pick up.

Returns ?WebRequest

abstract public function getName(): ?string

This validator’s declared name.

Returns ?``string

abstract public function getParentContainer(): ?IValidatorContainer

The container holding this validator.

Returns ?IValidatorContainer

abstract public function initialize(Context $context, array<string, mixed> $parameters = [], array<int|string, mixed> $arguments = [], array<int|string, mixed> $errors = []): mixed

Configure this validator from its declaration.

Error messages by index.

ParameterTypeDescription
$contextContext
$parametersarray``<``string``, ``mixed``>Validator parameters.
$arguments`array<int“string, mixed>`
$errors`array<int“string, mixed>`

Returns mixed

abstract public function setErrorMessage(string $index, string $message): void

Override the message reported for one error index.

ParameterTypeDescription
$indexstring
$messagestring

abstract public function setParentContainer(IValidatorContainer $parent): mixed

Attach this validator to its container.

ParameterTypeDescription
$parentIValidatorContainer

Returns mixed

abstract public function shutdown(): mixed

Release anything held for the duration of one validation run.

Returns mixed