PHP Class CRUDlex\EntityValidator

Show file Open project: philiplb/crudlex Class Usage Examples

Protected Properties

Property Type Description
$definition The entities definition.
$entity The entity to validate.

Public Methods

Method Description
__construct ( Entity $entity ) Constructor.
validate ( AbstractData $data, integer $expectedVersion ) : array Validates the entity against the definition.

Protected Methods

Method Description
buildUpData ( ) : array Builds up the data to validate from the entity.
buildUpRules ( AbstractData $data, Valdi\Validator $validator ) : array Builds up the validation rules for the entity according to its definition.
fieldConstraintsToRules ( string $field, AbstractData $data ) : array Builds up the validation rules for a single field according to the entity definition constraints.
fieldTypeToRules ( string $field, AbstractData $data, Valdi\Validator $validator ) : array Builds up the validation rules for a single field according to the entity definition type.

Method Details

__construct() public method

Constructor.
public __construct ( Entity $entity )
$entity Entity the entity to validate

buildUpData() protected method

Builds up the data to validate from the entity.
protected buildUpData ( ) : array
return array a map field to raw value

buildUpRules() protected method

Builds up the validation rules for the entity according to its definition.
protected buildUpRules ( AbstractData $data, Valdi\Validator $validator ) : array
$data AbstractData the data instance to use for validation
$validator Valdi\Validator the validator to use
return array the validation rules for the entity

fieldConstraintsToRules() protected method

Builds up the validation rules for a single field according to the entity definition constraints.
protected fieldConstraintsToRules ( string $field, AbstractData $data ) : array
$field string the field for the rules
$data AbstractData the data instance to use for validation
return array the validation rules for the field

fieldTypeToRules() protected method

Builds up the validation rules for a single field according to the entity definition type.
protected fieldTypeToRules ( string $field, AbstractData $data, Valdi\Validator $validator ) : array
$field string the field for the rules
$data AbstractData the data instance to use for validation
$validator Valdi\Validator the validator to use
return array the validation rules for the field

validate() public method

Validates the entity against the definition.
public validate ( AbstractData $data, integer $expectedVersion ) : array
$data AbstractData the data access instance used for counting things
$expectedVersion integer the version to perform the optimistic locking check on
return array an array with the fields "valid" and "errors"; valid provides a quick check whether the given entity passes the validation and errors is an array with all errored fields as keys and arrays as values; this field arrays contains the actual errors on the field: "boolean", "floating", "integer", "dateTime" (for dates and datetime fields), "inSet", "reference", "required", "unique", "value" (only for the version field, set if the optimistic locking failed).

Property Details

$definition protected property

The entities definition.
protected $definition

$entity protected property

The entity to validate.
protected $entity