ServerSideValidator extends Validator implements ServerSideValidatorInterface
ServerSideValidator Class.
Loads validation rules from a schema and validates a target array of data.
Tags
Table of Contents
$schema | RequestSchemaInterface | |
---|---|---|
$translator | Translator | |
__construct() | Create a new server-side validator. | mixed |
setSchema() | Set the schema for this validator, as a valid RequestSchemaInterface object. | mixed |
setTranslator() | Set the translator for this validator, as a valid Translator object. | mixed |
validate() | Validate the specified data against the schema rules. | bool |
hasRule() | {@inheritdoc} | mixed |
validateEqualsValue() | Validate that a field has a particular value. | bool |
validateNotEqualsValue() | Validate that a field does NOT have a particular value. | bool |
validatePhoneUS() | Matches US phone number format Ported from jqueryValidation rules. | bool |
validateUsername() | Validate that a field contains only valid username characters: alpha-numeric characters, dots, dashes, and underscores. | bool |
ruleWithMessage() | Add a rule to the validator, along with a specified error message if that rule is failed by the data. | mixed |
generateSchemaRules() | Generate and add rules from the schema. | mixed |
Properties
$schema
protected
RequestSchemaInterface
$schema
$translator
protected
Translator
$translator
Methods
__construct()
Create a new server-side validator.
public
__construct(
$schema :
RequestSchemaInterface
, $translator :
Translator
)
: mixed
Parameters
- $schema : RequestSchemaInterface
A RequestSchemaInterface object, containing the validation rules.
- $translator : Translator
A Translator to be used to translate message ids found in the schema.
Return values
mixedsetSchema()
Set the schema for this validator, as a valid RequestSchemaInterface object.
public
setSchema(
$schema :
RequestSchemaInterface
)
: mixed
Parameters
- $schema : RequestSchemaInterface
A RequestSchemaInterface object, containing the validation rules.
Return values
mixedsetTranslator()
Set the translator for this validator, as a valid Translator object.
public
setTranslator(
$translator :
Translator
)
: mixed
Parameters
- $translator : Translator
A Translator to be used to translate message ids found in the schema.
Return values
mixedvalidate()
Validate the specified data against the schema rules.
public
validate(
[ $data :
array
= [] ]
)
: bool
Parameters
- $data : array = []
An array of data, mapping field names to field values.
Return values
bool —True if the data was successfully validated, false otherwise.
hasRule()
{@inheritdoc}
public
hasRule(
$name :
mixed
, $field :
mixed
)
: mixed
We expose this method to the public interface for testing purposes.
Parameters
- $name : mixed
- $field : mixed
Return values
mixedvalidateEqualsValue()
Validate that a field has a particular value.
protected
validateEqualsValue(
$field :
string
, $value :
mixed
, $params :
array
)
: bool
Parameters
- $field : string
- $value : mixed
- $params : array
Return values
boolvalidateNotEqualsValue()
Validate that a field does NOT have a particular value.
protected
validateNotEqualsValue(
$field :
string
, $value :
mixed
, $params :
array
)
: bool
Parameters
- $field : string
- $value : mixed
- $params : array
Return values
boolvalidatePhoneUS()
Matches US phone number format Ported from jqueryValidation rules.
protected
validatePhoneUS(
$field :
string
, $value :
mixed
)
: bool
where the area code may not start with 1 and the prefix may not start with 1 allows '-' or ' ' as a separator and allows parens around area code some people may want to put a '1' in front of their number
1(212)-999-2345 or 212 999 2344 or 212-999-0983
but not 111-123-5434 and not 212 123 4567
Parameters
- $field : string
- $value : mixed
Return values
boolvalidateUsername()
Validate that a field contains only valid username characters: alpha-numeric characters, dots, dashes, and underscores.
protected
validateUsername(
$field :
string
, $value :
mixed
)
: bool
Parameters
- $field : string
- $value : mixed
Return values
boolruleWithMessage()
Add a rule to the validator, along with a specified error message if that rule is failed by the data.
protected
ruleWithMessage(
$rule :
string
, $messageSet :
string|null
)
: mixed
Parameters
- $rule : string
The name of the validation rule.
- $messageSet : string|null
The message to display when validation against this rule fails.
Return values
mixedgenerateSchemaRules()
Generate and add rules from the schema.
protected
generateSchemaRules(
)
: mixed