Exemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function validateField($field, $data)
 {
     // Retrieve field's value
     $value = $this->getFieldValue($field, $data);
     // Constraints
     $constraints = $this->getDefinition()->getConstraints($field, $value, $data);
     // Combine field validations
     $combinedFieldValidation = new CompoundValidation($field);
     foreach ($constraints as $key => $validator) {
         /** @var ValidatorInterface $validator */
         $combinedFieldValidation->add($field . '-' . $key, $validator->validate($value, $data));
     }
     return $combinedFieldValidation;
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function validate($data)
 {
     $this->data = $data;
     $fullValidation = new CompoundValidation();
     foreach ($this->getDefinition()->getFields() as $field) {
         // Retrieve field's value
         $value = $this->getFieldValue($field);
         // Constraints
         $constraints = $this->getDefinition()->getConstraints($field, $value, $data);
         // Combine field validations
         $combinedFieldValidation = new CompoundValidation($field);
         foreach ($constraints as $key => $validator) {
             $combinedFieldValidation->add($field . '-' . $key, $validator->validate($value, $data));
         }
         // Add to full validation
         $fullValidation->add($field, $combinedFieldValidation);
     }
     return $fullValidation;
 }