src/CRUDlex/EntityValidator.php
public function validate(AbstractData $data, $expectedVersion)
    {
        $validator = new Validator();
        $validator->addValidator('unique', new UniqueValidator());
        $validator->addValidator('reference', new ReferenceValidator());
        $validator->addValidator('many', new ManyValidator());
        $rules      = $this->buildUpRules($data, $validator);
        $toValidate = $this->buildUpData();
        if ($this->definition->hasOptimisticLocking()) {
            $rules['version']      = [['value', $expectedVersion]];
            $toValidate['version'] = $this->entity->get('version');
        }
        $validation = $validator->isValid($rules, $toValidate);
        return $validation;
    }
public function validate(AbstractData $data, $expectedVersion)
    {
        $validator = new Validator();
        $validator->addValidator('unique', new UniqueValidator());
        $validator->addValidator('reference', new ReferenceValidator());
        $validator->addValidator('many', new ManyValidator());
        $rules      = $this->buildUpRules($data, $validator);
        $toValidate = $this->buildUpData();
        if ($this->definition->hasOptimisticLocking()) {
            $rules['version']      = [['value', $expectedVersion]];
            $toValidate['version'] = $this->entity->get('version');
        }
        $validation = $validator->isValid($rules, $toValidate);
        return $validation;
    }
public function validate ( AbstractData $ data , $ expectedVersion ) { $ validator = new Validator ( ) ; $ validator -> addValidator ( 'unique' , new UniqueValidator ( ) ) ; $ validator -> addValidator ( 'reference' , new ReferenceValidator ( ) ) ; $ validator -> addValidator ( 'many' , new ManyValidator ( ) ) ; $ rules = $ this -> buildUpRules ( $ data , $ validator ) ; $ toValidate = $ this -> buildUpData ( ) ; if ( $ this -> definition -> hasOptimisticLocking ( ) ) { $ rules [ 'version' ] = [ [ 'value' , $ expectedVersion ] ] ; $ toValidate [ 'version' ] = $ this -> entity -> get ( 'version' ) ; } $ validation = $ validator -> isValid ( $ rules , $ toValidate ) ; return $ validation ; }
Validates the entity against the definition.

@param AbstractData $data
the data access instance used for counting things
@param integer $expectedVersion
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).
Validates the entity against the definition .