class Collection

@author Bernhard Schussek <bschussek@gmail.com>

@api

Hierarchy

  • class \Symfony\Component\Validator\Constraint
    • class \Symfony\Component\Validator\Constraints\Collection

Expanded class hierarchy of Collection

5 files declare their use of Collection
AnnotationLoaderTest.php in drupal/core/vendor/symfony/validator/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderTest.php
CollectionTest.php in drupal/core/vendor/symfony/validator/Symfony/Component/Validator/Tests/Constraints/CollectionTest.php
CollectionValidatorTest.php in drupal/core/vendor/symfony/validator/Symfony/Component/Validator/Tests/Constraints/CollectionValidatorTest.php
XmlFileLoaderTest.php in drupal/core/vendor/symfony/validator/Symfony/Component/Validator/Tests/Mapping/Loader/XmlFileLoaderTest.php
YamlFileLoaderTest.php in drupal/core/vendor/symfony/validator/Symfony/Component/Validator/Tests/Mapping/Loader/YamlFileLoaderTest.php
1 string reference to 'Collection'
EasyRdf_Parser_RdfXml::startState2 in drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/RdfXml.php
@ignore

File

drupal/core/vendor/symfony/validator/Symfony/Component/Validator/Constraints/Collection.php, line 26

Namespace

Symfony\Component\Validator\Constraints
View source
class Collection extends Constraint {
  public $fields;
  public $allowExtraFields = false;
  public $allowMissingFields = false;
  public $extraFieldsMessage = 'This field was not expected.';
  public $missingFieldsMessage = 'This field is missing.';

  /**
   * {@inheritDoc}
   */
  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);
    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) {
      if (!$field instanceof Optional && !$field instanceof Required) {
        $this->fields[$fieldName] = $field = new Required($field);
      }
      if (!is_array($field->constraints)) {
        $field->constraints = array(
          $field->constraints,
        );
      }
      foreach ($field->constraints as $constraint) {
        if (!$constraint instanceof Constraint) {
          throw new ConstraintDefinitionException(sprintf('The value %s of the field %s is not an instance of Constraint in constraint %s', $constraint, $fieldName, __CLASS__));
        }
        if ($constraint instanceof Valid) {
          throw new ConstraintDefinitionException(sprintf('The constraint Valid cannot be nested inside constraint %s. You can only declare the Valid constraint directly on a field or method.', __CLASS__));
        }
      }
    }
  }
  public function getRequiredOptions() {
    return array(
      'fields',
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Collection::$allowExtraFields public property
Collection::$allowMissingFields public property
Collection::$extraFieldsMessage public property
Collection::$fields public property
Collection::$missingFieldsMessage public property
Collection::getRequiredOptions public function Returns the name of the required options Overrides Constraint::getRequiredOptions
Collection::__construct public function Initializes the constraint with options. Overrides Constraint::__construct
Constraint::$groups public property
Constraint::addImplicitGroupName public function Adds the given group if this constraint is in the Default group
Constraint::CLASS_CONSTRAINT constant Marks a constraint that can be put onto classes
Constraint::DEFAULT_GROUP constant The name of the group given to all constraints with no explicit group
Constraint::getDefaultOption public function Returns the name of the default option 12
Constraint::getTargets public function Returns whether the constraint can be put onto classes, properties or both 7
Constraint::PROPERTY_CONSTRAINT constant Marks a constraint that can be put onto properties
Constraint::validatedBy public function Returns the name of the class that validates this constraint 2
Constraint::__set public function Unsupported operation.