Overview
Every programming language is different, but every language also has simalarities. This is a guide for creating Mystique validators in any language such that the syntax is similar an consistent across all implementations.
These conventions should be followed as much as the chosen language permits.
Base
The foundation object for all validators
The base object must act like an abstract class.
Constructor
The constructor may take a single argument called options
. Options should be an associative array of options to configure the validator.
Methods
Base must have the following methods:
public isValid(value)
This method requests the validation of value
. It must return a Result
object.
protected _isValid(value)
This method is the extension point for inheriting validators to place custom validation logic.
Properties
haltOnPass
Boolean
. Controls validator behaviour when part of a Chain
. Setting to true will stop any Validators after this one in the Chain from executing if this validator passes.
haltOnFail
Boolean
. Controls validator behaviour when part of a Chain
. Setting to true will stop any Validators after this one in the Chain from executing if this validator fails.
skipOnPass
Boolean
. Controls validator behaviour when part of a Chain
. Setting to true will skip evaluating this validator, if all previous validators have passed.
skipOnFail
Boolean
. Controls validator behaviour when part of a Chain
. Setting to true will skip evaluating this validator, if any previous validator has failed.
Result
The object returned by all validators
Constructor
The constructor may take a single argument called options
. Options should be an associative array of options to set Result properties. value
and messages
properties must be setable from this array
Methods
Result must have the following methods:
public addMessage(message)
Adds a message to the messages array. The message may be a string or array.
Properties
value
Boolean
. The outcome of the validation, ture or false.
messages
Array
. Any messages. If localization support is available, these messages should be localized.
Chain
A validator made from validators chained together.
A Chain must act like a subclass of Base.
Calling isValid
on a Chain object must evaluate the validators in the validators
property in order whilst respecting the haltOnPass
haltOnFail
skipOnPass
skipOnFail
properties of those validators.
Constructor
The constructor may take a single argument called options
. Options should be an associative array of options to set Chain properties. validators
property must be setable from this array.
Properties
validators
Array
. An array of validators to evaluate in order.