You are here

public function Collection::__construct in Zircon Profile 8

Same name in this branch
  1. 8 vendor/symfony/validator/Constraints/Collection.php \Symfony\Component\Validator\Constraints\Collection::__construct()
  2. 8 vendor/phpdocumentor/reflection-docblock/src/phpDocumentor/Reflection/DocBlock/Type/Collection.php \phpDocumentor\Reflection\DocBlock\Type\Collection::__construct()
Same name and namespace in other branches
  1. 8.0 vendor/symfony/validator/Constraints/Collection.php \Symfony\Component\Validator\Constraints\Collection::__construct()

The groups of the composite and its nested constraints are made consistent using the following strategy:

  • If groups are passed explicitly to the composite constraint, but not to the nested constraints, the options of the composite constraint are copied to the nested constraints;
  • If groups are passed explicitly to the nested constraints, but not to the composite constraint, the groups of all nested constraints are merged and used as groups for the composite constraint;
  • If groups are passed explicitly to both the composite and its nested constraints, the groups of the nested constraints must be a subset of the groups of the composite constraint. If not, a {@link ConstraintDefinitionException} is thrown.

All this is done in the constructor, because constraints can then be cached. When constraints are loaded from the cache, no more group checks need to be done.

Overrides Composite::__construct

File

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

Class

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

Namespace

Symfony\Component\Validator\Constraints

Code

public function __construct($options = null) {

  // no known options set? $options is the fields array
  if (is_array($options) && !array_intersect(array_keys($options), array(
    'groups',
    'fields',
    'allowExtraFields',
    'allowMissingFields',
    'extraFieldsMessage',
    'missingFieldsMessage',
  ))) {
    $options = array(
      'fields' => $options,
    );
  }
  parent::__construct($options);
}