PHP Class ZenValidator, silverstripe-zenvalidator

Author: ([email protected])
Inheritance: extends Validator
Show file Open project: sheadawson/silverstripe-zenvalidator Class Usage Examples

Protected Properties

Property Type Description
$constraints array constraints assigned to this validator
$defaultJS boolean
$parsleyEnabled boolean

Public Methods

Method Description
__construct ( array $constraints = [], boolean $parsleyEnabled = true, boolean $defaultJS = null )
addRequiredFields ( $fields ) : this A quick way of adding required constraints to a number of fields
applyParsley ( ) applyParsley
disableParsley ( ) : this disableParsley
fieldIsRequired ( string $fieldName ) : boolean Returns whether the field in question is required. This will usually display '*' next to the field.
getConstraint ( string $fieldName, string $constraintName ) : ZenValidatorConstraint get a constraint by fieldName, constraintName
getConstraints ( string $fieldName ) : array get constraints by fieldName
parsleyIsEnabled ( ) : boolean parsleyIsEnabled
php ( $data ) : boolean Performs the php validation on all ZenValidatorConstraints attached to this validator
removeAllValidation ( ) Removes all constraints from this validator.
removeConstraint ( $fieldName, string $constraintName ) remove a constraint from a field
removeConstraints ( $fieldName ) remove all constraints from a field
removeValidation ( ) This method is not imeplemented because form->transform calls it, but not all FormTransformations necessarily want to remove validation.
setConstraint ( $fieldName, ZenFieldValidator $constraint ) setConstraint - sets a ZenValidatorContraint on this validator
setConstraints ( array $constraints ) setConstraints - sets multiple constraints on this validator
setForm ( Form $form )

Method Details

__construct() public method

public __construct ( array $constraints = [], boolean $parsleyEnabled = true, boolean $defaultJS = null )
$constraints array
$parsleyEnabled boolean (default: true)
$defaultJS boolean (default: null)

addRequiredFields() public method

A quick way of adding required constraints to a number of fields
public addRequiredFields ( $fields ) : this
return this

applyParsley() public method

applyParsley
public applyParsley ( )

disableParsley() public method

disableParsley
public disableParsley ( ) : this
return this

fieldIsRequired() public method

Returns whether the field in question is required. This will usually display '*' next to the field.
public fieldIsRequired ( string $fieldName ) : boolean
$fieldName string
return boolean

getConstraint() public method

get a constraint by fieldName, constraintName
public getConstraint ( string $fieldName, string $constraintName ) : ZenValidatorConstraint
$fieldName string
$constraintName string
return ZenValidatorConstraint

getConstraints() public method

get constraints by fieldName
public getConstraints ( string $fieldName ) : array
$fieldName string
return array

parsleyIsEnabled() public method

parsleyIsEnabled
public parsleyIsEnabled ( ) : boolean
return boolean

php() public method

Performs the php validation on all ZenValidatorConstraints attached to this validator
public php ( $data ) : boolean
return boolean

removeAllValidation() public method

Removes all constraints from this validator.
public removeAllValidation ( )

removeConstraint() public method

remove a constraint from a field
public removeConstraint ( $fieldName, string $constraintName )
$constraintName string - class name of constraint

removeConstraints() public method

remove all constraints from a field
public removeConstraints ( $fieldName )

removeValidation() public method

.. right? Use removeAllValidation() instead.
public removeValidation ( )

setConstraint() public method

setConstraint - sets a ZenValidatorContraint on this validator
public setConstraint ( $fieldName, ZenFieldValidator $constraint )
$constraint ZenFieldValidator

setConstraints() public method

setConstraints - sets multiple constraints on this validator
public setConstraints ( array $constraints )
$constraints array - $fieldName => ZenValidatorConstraint

setForm() public method

public setForm ( Form $form )
$form Form

Property Details

$constraints protected property

constraints assigned to this validator
protected array $constraints
return array

$defaultJS protected property

protected bool $defaultJS
return boolean

$parsleyEnabled protected property

protected bool $parsleyEnabled
return boolean