Skip to content

ValidationManager

ValidationManager provides management for request parameters and their associated validators.

class ValidationManager extends ParameterHolder implements IValidatorContainer

ExtendsParameterHolder
ImplementsIValidatorContainer
Since1.0.0
SourceValidator/ValidationManager.php
ConstantValueDescription
MODE_CONDITIONAL'conditional'All request variables are available when no validation defined else only validated request variables are available.
MODE_RELAXED'relaxed'All request variables are always available.
MODE_STRICT'strict'Only validated request variables are available.
MethodDescription
addArgumentResult(ValidationArgument $argument, int $result, Validator $validator = null): voidAdds a intermediate result of an validator for the given argument
addChild(Validator $validator): mixedAdds a new child validator.
addFieldResult(Validator $validator, string $fieldname, int $result): voidAdds a validation result for a given field.
addIncident(ValidationIncident $incident): voidAdds an incident to the validation result.
clear(): voidClears the validation manager for reuse clears the validator manager by resetting the dependency and error manager and removing all validators after calling their shutdown method so they can do a save shutdown.
[`createValidator(class-string $class, array<intstring, mixed> $arguments, array<string, string> $errors = [], array<string, mixed> $parameters = [], ?IValidatorContainer $parent = null): T&Validator`](#createvalidator)
execute(WebRequest $request): boolStarts the validation process.
getBase(): VirtualArrayPathGets the base path of the validator.
getChild(string $name): mixedReturns a named child validator.
getChilds(): array<string, Validator>Returns all child validators.
getContext(): ContextRetrieve the current application context.
getDependencyManager(): DependencyManagerReturns the dependency manager.
getError(string $name): ?stringRetrieve an error message.
getErrorMessages(string $name = null): array<int, mixed>Retrieve an array of error Messages.
getErrorNames(): array<int, string>Retrieve an array of error names.
[`getErrors(string $name = null): array<string, mixed>null`](#geterrors)
getFailedFields(int $minSeverity = null): array<int, string>Returns all failed fields (this are all fields including those with severity none and notice).
getFieldErrorCode(string $fieldname, string $validatorName = null): ?intWill return the highest error code for a field.
getFieldErrors(string $fieldname, int $minSeverity = null): array<int, ValidationError>Returns all errors of a given field.
getFieldIncidents(string $fieldname, int $minSeverity = null): array<int, ValidationIncident>Returns all incidents of a given field.
getIncidents(int $minSeverity = null): array<int, ValidationIncident>Returns all incidents which happened during the execution of the validation.
getRawParameterSnapshot(): array<string, mixed>Framework-internal accessor for the raw, unvalidated parameters as submitted, captured before any pruning by execute().
getReport(): ValidationReportRetrieve the validation result report container of the last validation run.
getResult(): intReturns the final validation result.
getSucceededFields(string $source): array<int, string>Returns all fields which succeeded in the validation.
getValidatorFieldErrors(string $validatorName, string $fieldname, ?int $minSeverity = null): array<int, ValidationIncident>Returns all errors of a given field in a given validator.
getValidatorIncidents(string $validatorName, int $minSeverity = null): array<int, ValidationIncident>Returns all incidents of a given validator.
hasError(string $name): boolIndicates whether or not a field has an error.
hasErrors(): boolIndicates whether or not any errors exist.
hasIncidents(int $minSeverity = null): boolChecks if any incidents occurred Returns all fields which succeeded in the validation.
initialize(Context $context, array<string, mixed> $parameters = []): voidinitializes the validator manager.
isFieldFailed(string $fieldname): boolChecks whether a field has failed in any validator.
isFieldValidated(string $fieldname): boolChecks whether a field has been processed by a validator (this includes fields which were skipped because their value was not set and the validator was not required)
registerValidators(array<int, Validator> $validators): voidRegisters multiple validators.
reset(): voidReturns the manager to its initial state for reuse across requests.
setError(string $name, string $message): voidSet an error.
setErrors(array<string, string> $errors): voidSet an array of errors If an existing error name matches any of the keys in the supplied array, the associated message will be appended to the messages array.
shutdown(): voidShuts the validation system down.

public function addArgumentResult(ValidationArgument $argument, int $result, Validator $validator = null): void

Adds a intermediate result of an validator for the given argument

The validator (if the error was caused inside a validator).

ParameterTypeDescription
$argumentValidationArgumentThe argument
$resultintThe arguments result.
$validatorValidatorThe validator (if the error was caused inside a validator).

public function addChild(Validator $validator): mixed

Adds a new child validator.

The new child validator.

ParameterTypeDescription
$validatorValidatorThe new child validator.

Returns mixed

public function addFieldResult(Validator $validator, string $fieldname, int $result): void

Adds a validation result for a given field.

The result of the validation.

ParameterTypeDescription
$validatorValidatorThe validator.
$fieldnamestringThe name of the field which has been validated.
$resultintThe result of the validation.

public function addIncident(ValidationIncident $incident): void

Adds an incident to the validation result.

The incident.

ParameterTypeDescription
$incidentValidationIncidentThe incident.

public function clear(): void

Clears the validation manager for reuse clears the validator manager by resetting the dependency and error manager and removing all validators after calling their shutdown method so they can do a save shutdown.

public function createValidator(class-string<T> $class, array<int|string, mixed> $arguments, array<string, string> $errors = [], array<string, mixed> $parameters = [], ?IValidatorContainer $parent = null): T&Validator

Creates a new validator instance.

The parent (will use the validation manager if null is given)

ParameterTypeDescription
$classclass-string``<``T``>The name of the class implementing the validator.
$arguments`array<int“string, mixed>`
$errorsarray``<``string``, ``string``>The error messages.
$parametersarray``<``string``, ``mixed``>The validator parameters.
$parent?IValidatorContainerThe parent (will use the validation manager if null is given)

Returns T``&Validator

public function execute(WebRequest $request): bool

Starts the validation process.

The data which should be validated.

ParameterTypeDescription
$requestWebRequestThe data which should be validated.

Returns bool — true, if validation succeeded.

public function getBase(): VirtualArrayPath

Gets the base path of the validator.

Returns VirtualArrayPath — The base path.

public function getChild(string $name): mixed

Returns a named child validator.

The name of the child validator.

ParameterTypeDescription
$namestringThe name of the child validator.

Returns mixed

public function getChilds(): array<string, Validator>

Returns all child validators.

Returns array``<``string``, Validator> — An array of Validator instances.

final public function getContext(): Context

Retrieve the current application context.

Returns Context — The current Context instance.

public function getDependencyManager(): DependencyManager

Returns the dependency manager.

Returns DependencyManager — The dependency manager instance.

public function getError(string $name): ?string

Retrieve an error message.

An error name.

ParameterTypeDescription
$namestringAn error name.

Returns ?``string — The error message, or null if there is no such error.

public function getErrorMessages(string $name = null): array<int, mixed>

Retrieve an array of error Messages.

An optional error name.

ParameterTypeDescription
$namestringAn optional error name.

Returns array``<``int``, ``mixed``> — An indexed array of error messages (if a name was given) or an indexed array in this format: array(‘message’ => string, ‘errors’ => array(string))

public function getErrorNames(): array<int, string>

Retrieve an array of error names.

Returns array``<``int``, ``string``> — An indexed array of error names.

public function getErrors(string $name = null): array<string, mixed>|null

Retrieve an array of errors.

An optional error name.

ParameterTypeDescription
$namestringAn optional error name.

Returns array``<``string``, ``mixed``>``|``null — An associative array of errors(if no name was given) as an array with the error messages (key ‘messages’) and the validators (key ‘validators’) which failed.

public function getFailedFields(int $minSeverity = null): array<int, string>

Returns all failed fields (this are all fields including those with severity none and notice).

The minimum severity a field needs to have.

ParameterTypeDescription
$minSeverityintThe minimum severity a field needs to have.

Returns array``<``int``, ``string``> — The names of the fields.

public function getFieldErrorCode(string $fieldname, string $validatorName = null): ?int

Will return the highest error code for a field.

The Validator name

ParameterTypeDescription
$fieldnamestringThe name of the field.
$validatorNamestringThe Validator name

Returns ?``int — The error code, or null if the field was never touched by a validator.

public function getFieldErrors(string $fieldname, int $minSeverity = null): array<int, ValidationError>

Returns all errors of a given field.

The minimum severity a returned incident of the error needs to have.

ParameterTypeDescription
$fieldnamestringThe name of the field.
$minSeverityintThe minimum severity a returned incident of the error needs to have.

Returns array``<``int``, ValidationError> — The errors.

public function getFieldIncidents(string $fieldname, int $minSeverity = null): array<int, ValidationIncident>

Returns all incidents of a given field.

The minimum severity a returned incident needs to have.

ParameterTypeDescription
$fieldnamestringThe name of the field.
$minSeverityintThe minimum severity a returned incident needs to have.

Returns array``<``int``, ValidationIncident> — The incidents.

public function getIncidents(int $minSeverity = null): array<int, ValidationIncident>

Returns all incidents which happened during the execution of the validation.

The minimum severity a returned incident needs to have.

ParameterTypeDescription
$minSeverityintThe minimum severity a returned incident needs to have.

Returns array``<``int``, ValidationIncident> — The incidents.

public function getRawParameterSnapshot(): array<string, mixed>

Framework-internal accessor for the raw, unvalidated parameters as submitted, captured before any pruning by execute().

NOT reachable via WebRequest::getParameter()/getParameters() — this exists solely so FormPopulationEngine can redisplay a submitted value in an HTML form after a validation failure scrubbed it from the request (see the class docblock on $rawParameterSnapshot). Never use this for business logic.

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

public function getReport(): ValidationReport

Retrieve the validation result report container of the last validation run.

Returns ValidationReport — The result report container.

public function getResult(): int

Returns the final validation result.

Returns int — The result of the validation process.

public function getSucceededFields(string $source): array<int, string>

Returns all fields which succeeded in the validation.

The source for which the fields should be returned.

ParameterTypeDescription
$sourcestringThe source for which the fields should be returned.

Returns array``<``int``, ``string``> — An array of field names.

public function getValidatorFieldErrors(string $validatorName, string $fieldname, ?int $minSeverity = null): array<int, ValidationIncident>

Returns all errors of a given field in a given validator.

The minimum severity a returned incident of the error needs to have.

ParameterTypeDescription
$validatorNamestringThe name of the validator.
$fieldnamestringThe name of the field.
$minSeverity?``intThe minimum severity a returned incident of the error needs to have.

Returns array``<``int``, ValidationIncident> — The incidents.

public function getValidatorIncidents(string $validatorName, int $minSeverity = null): array<int, ValidationIncident>

Returns all incidents of a given validator.

The minimum severity a returned incident needs to have.

ParameterTypeDescription
$validatorNamestringThe name of the validator.
$minSeverityintThe minimum severity a returned incident needs to have.

Returns array``<``int``, ValidationIncident> — The incidents.

public function hasError(string $name): bool

Indicates whether or not a field has an error.

A field name.

ParameterTypeDescription
$namestringA field name.

Returns bool — true, if the field has an error, false otherwise.

public function hasErrors(): bool

Indicates whether or not any errors exist.

Returns bool — true, if any error exist, otherwise false.

public function hasIncidents(int $minSeverity = null): bool

Checks if any incidents occurred Returns all fields which succeeded in the validation.

The minimum severity which shall be checked for.

ParameterTypeDescription
$minSeverityintThe minimum severity which shall be checked for.

Returns bool — The result.

public function initialize(Context $context, array<string, mixed> $parameters = []): void

initializes the validator manager.

The initialization parameters.

ParameterTypeDescription
$contextContextThe context instance.
$parametersarray``<``string``, ``mixed``>The initialization parameters.

public function isFieldFailed(string $fieldname): bool

Checks whether a field has failed in any validator.

The name of the field.

ParameterTypeDescription
$fieldnamestringThe name of the field.

Returns bool — Whether the field has failed.

public function isFieldValidated(string $fieldname): bool

Checks whether a field has been processed by a validator (this includes fields which were skipped because their value was not set and the validator was not required)

The name of the field.

ParameterTypeDescription
$fieldnamestringThe name of the field.

Returns bool — Whether the field was validated.

public function registerValidators(array<int, Validator> $validators): void

Registers multiple validators.

An array of validators.

ParameterTypeDescription
$validatorsarray``<``int``, Validator>An array of validators.

public function reset(): void

Returns the manager to its initial state for reuse across requests.

Resets and then detaches every registered validator, clears the dependency manager, and installs a fresh report, so results and incidents from the previous run cannot leak into the next one. The manager’s own parameters are left alone; validators must be registered again before execute() has anything to run.

public function setError(string $name, string $message): void

Set an error.

An error message.

ParameterTypeDescription
$namestringAn error name.
$messagestringAn error message.

public function setErrors(array<string, string> $errors): void

Set an array of errors If an existing error name matches any of the keys in the supplied array, the associated message will be appended to the messages array.

An associative array of errors and their associated messages.

ParameterTypeDescription
$errorsarray``<``string``, ``string``>An associative array of errors and their associated messages.

public function shutdown(): void

Shuts the validation system down.

These come from an ancestor and are documented where they are declared.

MethodDeclared inDescription
appendParameter()ParameterHolderAppend a parameter.
appendParameterByRef()ParameterHolderAppend a parameter by reference.
clearParameters()ParameterHolderClear all parameters associated with this request.
getFlatParameterNames()ParameterHolderRetrieve an array of flattened parameter names.
getParameter()ParameterHolderRetrieve a parameter.
getParameterNames()ParameterHolderRetrieve an array of parameter names.
getParameters()ParameterHolderRetrieve an array of parameters.
hasParameter()ParameterHolderIndicates whether or not a parameter exists.
removeParameter()ParameterHolderRemove a parameter.
setParameter()ParameterHolderSet a parameter.
setParameterByRef()ParameterHolderSet a parameter by reference.
setParameters()ParameterHolderSet an array of parameters.
setParametersByRef()ParameterHolderSet an array of parameters by reference.