OperatorValidator
OperatorValidator Operators group a couple if validators…
Synopsis
Section titled “Synopsis”abstract class OperatorValidator extends Validator implements IValidatorContainer
| Extends | Validator |
| Implements | IValidatorContainer |
| Since | 1.0.0 |
| Source | Validator/OperatorValidator.php |
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
$children | mixed | protected. |
$result | mixed | protected. |
Methods
Section titled “Methods”| Method | Description |
|---|---|
addArgumentResult(ValidationArgument $argument, int $result, Validator $validator = null): null | Adds a intermediate result of an validator for the given argument. |
addChild(Validator $validator): void | Adds new child validator. |
addFieldResult(Validator $validator, string $fieldname, int $result): mixed | Adds a validation result for a given field. |
addIncident(ValidationIncident $incident): null | Adds an incident to the validation result. |
checkValidSetup(): void | Method for checking the validity of child validators. |
execute(WebRequest $parameters): int | Executes the validator. |
getAcceptedParameters(): array<int, string> | Returns the base Validator parameters plus ‘skip_errors’, shared by every operator. |
getChild(string $name): Validator | Returns a named child validator. |
getChilds(): array<string, Validator> | Returns all child validators. |
getDependencyManager(): DependencyManager | Gets parent’s dependency manager. |
getResult(): int | Returns the result from the error manager. |
registerValidators(array<Validator> $validators): void | Registers an array of validators. |
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. |
reset(): void | Returns the operator to its initial state for reuse across requests. |
shutdown(): void | Shutdown method, for shutting down the model etc. |
addArgumentResult()
Section titled “addArgumentResult()”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).
| Parameter | Type | Description |
|---|---|---|
$argument | ValidationArgument | The argument |
$result | int | The arguments result. |
$validator | Validator | The validator (if the error was caused inside a validator). |
Returns null
addChild()
Section titled “addChild()”public function addChild(Validator $validator): void
Adds new child validator.
The new child validator.
| Parameter | Type | Description |
|---|---|---|
$validator | Validator | The new child validator. |
addFieldResult()
Section titled “addFieldResult()”public function addFieldResult(Validator $validator, string $fieldname, int $result): mixed
Adds a validation result for a given field.
The result of the validation.
| Parameter | Type | Description |
|---|---|---|
$validator | Validator | The validator. |
$fieldname | string | The name of the field which has been validated. |
$result | int | The result of the validation. |
Returns mixed
addIncident()
Section titled “addIncident()”public function addIncident(ValidationIncident $incident): null
Adds an incident to the validation result.
The incident.
| Parameter | Type | Description |
|---|---|---|
$incident | ValidationIncident | The incident. |
Returns null
checkValidSetup()
Section titled “checkValidSetup()”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.
| Throws | When |
|---|---|
ValidatorException | If the quantity of child validators is invalid |
execute()
Section titled “execute()”public function execute(WebRequest $parameters): int
Executes the validator.
The parameters which should be validated.
| Parameter | Type | Description |
|---|---|---|
$parameters | WebRequest | The parameters which should be validated. |
Returns int — The result of validation (SUCCESS, NONE, NOTICE, ERROR, CRITICAL).
getAcceptedParameters()
Section titled “getAcceptedParameters()”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.
getChild()
Section titled “getChild()”public function getChild(string $name): Validator
Returns a named child validator.
The name of the child validator.
| Parameter | Type | Description |
|---|---|---|
$name | string | The name of the child validator. |
Returns Validator — The named child validator.
getChilds()
Section titled “getChilds()”public function getChilds(): array<string, Validator>
Returns all child validators.
Returns array``<``string``, Validator> — An array of Validator instances.
getDependencyManager()
Section titled “getDependencyManager()”public function getDependencyManager(): DependencyManager
Gets parent’s dependency manager.
Returns DependencyManager — The parent’s dependency manager.
getResult()
Section titled “getResult()”public function getResult(): int
Returns the result from the error manager.
Returns int — The result of the validation process.
registerValidators()
Section titled “registerValidators()”public function registerValidators(array<Validator> $validators): void
Registers an array of validators.
The array of validators.
| Parameter | Type | Description |
|---|---|---|
$validators | array``<Validator> | The array of validators. |
requireValidationParameters()
Section titled “requireValidationParameters()”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().
reset()
Section titled “reset()”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.
shutdown()
Section titled “shutdown()”public function shutdown(): void
Shutdown method, for shutting down the model etc.
Inherited methods
Section titled “Inherited methods”These come from an ancestor and are documented where they are declared.
| Method | Declared in | Description |
|---|---|---|
appendParameter() | ParameterHolder | Append a parameter. |
appendParameterByRef() | ParameterHolder | Append a parameter by reference. |
clearParameters() | ParameterHolder | Clear all parameters associated with this request. |
getArguments() | Validator | Returns all arguments which should be validated. |
getBase() | Validator | Returns the base path of this validator. |
getBaseKeys() | Validator | Returns the “keys” in the path of the base |
getContext() | Validator | Retrieve the current application context. |
getFlatParameterNames() | ParameterHolder | Retrieve an array of flattened parameter names. |
getLastKey() | Validator | Returns the last “keys” in the path of the base |
getMutatedRequest() | Validator | The WebRequest this validator ended execute() with. |
getName() | Validator | Returns the name of this validator. |
getParameter() | ParameterHolder | Retrieve a parameter. |
getParameterNames() | ParameterHolder | Retrieve an array of parameter names. |
getParameters() | ParameterHolder | Retrieve an array of parameters. |
getParentContainer() | Validator | Retrieve the parent container. |
hasParameter() | ParameterHolder | Indicates whether or not a parameter exists. |
initialize() | Validator | Initialize this validator. |
mapErrorCode() | Validator | Converts 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() | ParameterHolder | Remove a parameter. |
setErrorMessage() | Validator | Sets an error message override for the given index (the empty string is the default/generic message). |
setParameter() | ParameterHolder | Set a parameter. |
setParameterByRef() | ParameterHolder | Set a parameter by reference. |
setParameters() | ParameterHolder | Set an array of parameters. |
setParametersByRef() | ParameterHolder | Set an array of parameters by reference. |
setParentContainer() | Validator | Sets the parent container. |