Skip to content

OperatorValidator

OperatorValidator Operators group a couple if validators…

abstract class OperatorValidator extends Validator implements IValidatorContainer

ExtendsValidator
ImplementsIValidatorContainer
Since1.0.0
SourceValidator/OperatorValidator.php
PropertyTypeDescription
$childrenmixedprotected.
$resultmixedprotected.
MethodDescription
addArgumentResult(ValidationArgument $argument, int $result, Validator $validator = null): nullAdds a intermediate result of an validator for the given argument.
addChild(Validator $validator): voidAdds new child validator.
addFieldResult(Validator $validator, string $fieldname, int $result): mixedAdds a validation result for a given field.
addIncident(ValidationIncident $incident): nullAdds an incident to the validation result.
checkValidSetup(): voidMethod for checking the validity of child validators.
execute(WebRequest $parameters): intExecutes the validator.
getAcceptedParameters(): array<int, string>Returns the base Validator parameters plus ‘skip_errors’, shared by every operator.
getChild(string $name): ValidatorReturns a named child validator.
getChilds(): array<string, Validator>Returns all child validators.
getDependencyManager(): DependencyManagerGets parent’s dependency manager.
getResult(): intReturns the result from the error manager.
registerValidators(array<Validator> $validators): voidRegisters an array of validators.
requireValidationParameters(): WebRequestNarrows $validationParameters (inherited from Validator, and typed nullable there because it’s only populated once execute() runs) to a concrete WebRequest for dispatching to child validators.
reset(): voidReturns the operator to its initial state for reuse across requests.
shutdown(): voidShutdown method, for shutting down the model etc.

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

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).

Returns null

public function addChild(Validator $validator): void

Adds new child validator.

The new child validator.

ParameterTypeDescription
$validatorValidatorThe new child validator.

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

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.

Returns mixed

public function addIncident(ValidationIncident $incident): null

Adds an incident to the validation result.

The incident.

ParameterTypeDescription
$incidentValidationIncidentThe incident.

Returns null

protected function checkValidSetup(): void

Method for checking the validity of child validators.

Some operators (XOR and NOT) need a specific quantity of child validators so they implement an algorithm that checks of the setup is valid. This method is run first when execute() is invoked and should throw an exception if the setup is invalid.

ThrowsWhen
ValidatorExceptionIf the quantity of child validators is invalid

public function execute(WebRequest $parameters): int

Executes the validator.

The parameters which should be validated.

ParameterTypeDescription
$parametersWebRequestThe parameters which should be validated.

Returns int — The result of validation (SUCCESS, NONE, NOTICE, ERROR, CRITICAL).

public static function getAcceptedParameters(): array<int, string>

Returns the base Validator parameters plus ‘skip_errors’, shared by every operator.

‘skip_errors’ keeps a child’s CRITICAL result from being promoted to this group’s own result, so a critical failure inside the group does not abort validation in the surrounding container. Concrete operators merge their own names onto this set.

Returns array``<``int``, ``string``> — The accepted parameter names.

public function getChild(string $name): Validator

Returns a named child validator.

The name of the child validator.

ParameterTypeDescription
$namestringThe name of the child validator.

Returns Validator — The named child validator.

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

Returns all child validators.

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

public function getDependencyManager(): DependencyManager

Gets parent’s dependency manager.

Returns DependencyManager — The parent’s dependency manager.

public function getResult(): int

Returns the result from the error manager.

Returns int — The result of the validation process.

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

Registers an array of validators.

The array of validators.

ParameterTypeDescription
$validatorsarray``<Validator>The array of validators.

protected function requireValidationParameters(): WebRequest

Narrows $validationParameters (inherited from Validator, and typed nullable there because it’s only populated once execute() runs) to a concrete WebRequest for dispatching to child validators.

Only ever null before this operator’s own execute() has run, which validate() always happens after.

Returns WebRequest — The request supplied to this operator’s execute().

public function reset(): void

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

Resets every child first, then detaches them all, puts the accumulated result back to SUCCESS and discards the argument results and incidents that were being held back for the deferred flush. Children are not kept, so a reset operator validates nothing until it is registered again.

public function shutdown(): void

Shutdown method, for shutting down the model etc.

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.
getArguments()ValidatorReturns all arguments which should be validated.
getBase()ValidatorReturns the base path of this validator.
getBaseKeys()ValidatorReturns the “keys” in the path of the base
getContext()ValidatorRetrieve the current application context.
getFlatParameterNames()ParameterHolderRetrieve an array of flattened parameter names.
getLastKey()ValidatorReturns the last “keys” in the path of the base
getMutatedRequest()ValidatorThe WebRequest this validator ended execute() with.
getName()ValidatorReturns the name of this validator.
getParameter()ParameterHolderRetrieve a parameter.
getParameterNames()ParameterHolderRetrieve an array of parameter names.
getParameters()ParameterHolderRetrieve an array of parameters.
getParentContainer()ValidatorRetrieve the parent container.
hasParameter()ParameterHolderIndicates whether or not a parameter exists.
initialize()ValidatorInitialize this validator.
mapErrorCode()ValidatorConverts string severity codes into integer values (see severity constants) critical -> Validator::CRITICAL error -> Validator::ERROR notice -> Validator::NOTICE none -> Validator::NONE success -> not allowed to be specified by the user.
removeParameter()ParameterHolderRemove a parameter.
setErrorMessage()ValidatorSets an error message override for the given index (the empty string is the default/generic message).
setParameter()ParameterHolderSet a parameter.
setParameterByRef()ParameterHolderSet a parameter by reference.
setParameters()ParameterHolderSet an array of parameters.
setParametersByRef()ParameterHolderSet an array of parameters by reference.
setParentContainer()ValidatorSets the parent container.