-
Notifications
You must be signed in to change notification settings - Fork 0
Docs Request Validators
All validators implement the net::stubbles::ipo::request::validator::stubValidator interface. Every validator offers the validate($value) method. It takes the value to validate and returns true if the value fulfils the criteria of the validator and false if not. The other method available is getCriterias() which returns an associative array of the criteria used to validate the value.
Stubbles provides the following validators in the net::stubbles::ipo::request::validator package:
- net::stubbles::ipo::request::validator::stubContainsValidator compares any scalar value with an expected value. The value to validate has to be of the same type and should have the same content as the expected value.
- net::stubbles::ipo::request::validator::stubDenyValidator denies validaty of values, i.e. returns always false.
- net::stubbles::ipo::request::validator::stubEqualValidator compares any scalar value with an expected value. The value to validate has to be of the same type and should have the same content as the expected value.
- net::stubbles::ipo::request::validator::stubExtFilterValidator wraps the validators provided by ext/filter.
- net::stubbles::ipo::request::validator::stubHTTPURLValidator validates that the value is an HTTP URL, optionally checks if a DNS entry is present.
- net::stubbles::ipo::request::validator::stubIpValidator validates that something is an IP address.
- net::stubbles::ipo::request::validator::stubMailValidator ensures that a string is a mail address.
- net::stubbles::ipo::request::validator::stubMaxLengthValidator ensures that a string is not longer than a given maximum length.
- net::stubbles::ipo::request::validator::stubMaxNumberValidator ensures that a value is not greater than a given maximum value.
- net::stubbles::ipo::request::validator::stubMinLengthValidator ensures that a string is not shorter than a given minimum length.
- net::stubbles::ipo::request::validator::stubMinNumberValidator ensures that a value is not smaller than a given minimum value.
- net::stubbles::ipo::request::validator::stubPassThruValidator returns always true regardless of the value to validate.
- net::stubbles::ipo::request::validator::stubPreSelectValidator validates a value against a list of allowed values.
- net::stubbles::ipo::request::validator::stubRegexValidator ensures a value complies to a given regular expression.
It is possible to combine any validator to one big validator:
- net::stubbles::ipo::request::validator::stubAndValidator validates that a value is valid in all of the added validators.
- net::stubbles::ipo::request::validator::stubOrValidator validates that a value is valid in one of the added validators.
- net::stubbles::ipo::request::validator::stubXorValidator validates that a value is valid in exactly one of the added validators.
A validator can be added to them via the addValidator(stubValidator $validator) method.
To create a validator it has to implement the net::stubbles::ipo::request::validator::stubValidator interface. Within the validate($value) method any check required can be performed. If all checks are satisfied with the content of $value it should return true, if not return false to indicate that something is wrong the value.