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.
Synopsis
Section titled “Synopsis”interface ValidatorInterface
| Implemented by | Validator |
| Since | 3.2.0 |
| Source | Validator/ValidatorInterface.php |
Methods
Section titled “Methods”| Method | Description |
|---|---|
execute(WebRequest $parameters): int | Run this validator against $parameters. |
| [`getArguments(): array<int | string, mixed>`](#getarguments) |
getBase(): mixed | The base path relative argument names resolve against. |
getDependencyManager(): ?DependencyManager | The dependency manager coordinating provides/depends between validators. |
getMutatedRequest(): ?WebRequest | The request this validator produced, when it exported values, or null when it changed nothing. |
getName(): ?string | This validator’s declared name. |
getParentContainer(): ?IValidatorContainer | The container holding this validator. |
| [`initialize(Context $context, array<string, mixed> $parameters = [], array<int | string, mixed> $arguments = [], array<int |
setErrorMessage(string $index, string $message): void | Override the message reported for one error index. |
setParentContainer(IValidatorContainer $parent): mixed | Attach this validator to its container. |
shutdown(): mixed | Release anything held for the duration of one validation run. |
execute()
Section titled “execute()”abstract public function execute(WebRequest $parameters): int
Run this validator against $parameters.
| Parameter | Type | Description |
|---|---|---|
$parameters | WebRequest |
Returns int — The validation result code.
getArguments()
Section titled “getArguments()”abstract public function getArguments(): array<int|string, mixed>
The argument names this validator targets.
Returns array``<``int``|``string``, ``mixed``>
getBase()
Section titled “getBase()”abstract public function getBase(): mixed
The base path relative argument names resolve against.
Returns mixed
getDependencyManager()
Section titled “getDependencyManager()”abstract public function getDependencyManager(): ?DependencyManager
The dependency manager coordinating provides/depends between validators.
Returns ?DependencyManager
getMutatedRequest()
Section titled “getMutatedRequest()”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
getName()
Section titled “getName()”abstract public function getName(): ?string
This validator’s declared name.
Returns ?``string
getParentContainer()
Section titled “getParentContainer()”abstract public function getParentContainer(): ?IValidatorContainer
The container holding this validator.
Returns ?IValidatorContainer
initialize()
Section titled “initialize()”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.
| Parameter | Type | Description |
|---|---|---|
$context | Context | |
$parameters | array``<``string``, ``mixed``> | Validator parameters. |
$arguments | `array<int“ | string, mixed>` |
$errors | `array<int“ | string, mixed>` |
Returns mixed
setErrorMessage()
Section titled “setErrorMessage()”abstract public function setErrorMessage(string $index, string $message): void
Override the message reported for one error index.
| Parameter | Type | Description |
|---|---|---|
$index | string | |
$message | string |
setParentContainer()
Section titled “setParentContainer()”abstract public function setParentContainer(IValidatorContainer $parent): mixed
Attach this validator to its container.
| Parameter | Type | Description |
|---|---|---|
$parent | IValidatorContainer |
Returns mixed
shutdown()
Section titled “shutdown()”abstract public function shutdown(): mixed
Release anything held for the duration of one validation run.
Returns mixed