You are here

protected function Collection::initializeNestedConstraints in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/validator/Constraints/Collection.php \Symfony\Component\Validator\Constraints\Collection::initializeNestedConstraints()

Initializes the nested constraints.

This method can be overwritten in subclasses to clean up the nested constraints passed to the constructor.

Overrides Composite::initializeNestedConstraints

See also

Collection::initializeNestedConstraints()

File

vendor/symfony/validator/Constraints/Collection.php, line 55

Class

Collection
@Target({"PROPERTY", "METHOD", "ANNOTATION"})

Namespace

Symfony\Component\Validator\Constraints

Code

protected function initializeNestedConstraints() {
  parent::initializeNestedConstraints();
  if (!is_array($this->fields)) {
    throw new ConstraintDefinitionException(sprintf('The option "fields" is expected to be an array in constraint %s', __CLASS__));
  }
  foreach ($this->fields as $fieldName => $field) {

    // the XmlFileLoader and YamlFileLoader pass the field Optional
    // and Required constraint as an array with exactly one element
    if (is_array($field) && count($field) == 1) {
      $this->fields[$fieldName] = $field = $field[0];
    }
    if (!$field instanceof Optional && !$field instanceof Required) {
      $this->fields[$fieldName] = $field = new Required($field);
    }
  }
}