class Collection in Plug 7
@Target({"PROPERTY", "METHOD", "ANNOTATION"})
@author Bernhard Schussek <bschussek@gmail.com>
@api
Hierarchy
- class \Symfony\Component\Validator\Constraint
- class \Symfony\Component\Validator\Constraints\Composite
- class \Symfony\Component\Validator\Constraints\Collection
- class \Symfony\Component\Validator\Constraints\Composite
Expanded class hierarchy of Collection
6 files declare their use of Collection
- AnnotationLoaderTest.php in lib/
Symfony/ validator/ Symfony/ Component/ Validator/ Tests/ Mapping/ Loader/ AnnotationLoaderTest.php - CollectionTest.php in lib/
Symfony/ validator/ Symfony/ Component/ Validator/ Tests/ Constraints/ CollectionTest.php - CollectionValidatorTest.php in lib/
Symfony/ validator/ Symfony/ Component/ Validator/ Tests/ Constraints/ CollectionValidatorTest.php - LegacyExecutionContextTest.php in lib/
Symfony/ validator/ Symfony/ Component/ Validator/ Tests/ LegacyExecutionContextTest.php - XmlFileLoaderTest.php in lib/
Symfony/ validator/ Symfony/ Component/ Validator/ Tests/ Mapping/ Loader/ XmlFileLoaderTest.php
File
- lib/
Symfony/ validator/ Symfony/ Component/ Validator/ Constraints/ Collection.php, line 24
Namespace
Symfony\Component\Validator\ConstraintsView source
class Collection extends Composite {
const MISSING_FIELD_ERROR = 1;
const NO_SUCH_FIELD_ERROR = 2;
protected static $errorNames = array(
self::MISSING_FIELD_ERROR => 'MISSING_FIELD_ERROR',
self::NO_SUCH_FIELD_ERROR => 'NO_SUCH_FIELD_ERROR',
);
public $fields = array();
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);
}
/**
* {@inheritdoc}
*/
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);
}
}
}
public function getRequiredOptions() {
return array(
'fields',
);
}
protected function getCompositeOption() {
return 'fields';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Collection:: |
public | property | ||
Collection:: |
public | property | ||
Collection:: |
protected static | property |
Maps error codes to the names of their constants Overrides Constraint:: |
|
Collection:: |
public | property | ||
Collection:: |
public | property | ||
Collection:: |
public | property | ||
Collection:: |
protected | function |
Returns the name of the property that contains the nested constraints. Overrides Composite:: |
|
Collection:: |
public | function |
Returns the name of the required options. Overrides Constraint:: |
|
Collection:: |
protected | function |
Initializes the nested constraints. Overrides Composite:: |
|
Collection:: |
constant | |||
Collection:: |
constant | |||
Collection:: |
public | function |
The groups of the composite and its nested constraints are made
consistent using the following strategy: Overrides Composite:: |
|
Composite:: |
public | function |
Implicit group names are forwarded to nested constraints. Overrides Constraint:: |
|
Constraint:: |
public | property | Domain-specific data attached to a constraint | |
Constraint:: |
constant | Marks a constraint that can be put onto classes. | ||
Constraint:: |
constant | The name of the group given to all constraints with no explicit group. | ||
Constraint:: |
public | function | Returns the name of the default option. | 15 |
Constraint:: |
public static | function | Returns the name of the given error code. | |
Constraint:: |
public | function | Returns whether the constraint can be put onto classes, properties or both. | 11 |
Constraint:: |
constant | Marks a constraint that can be put onto properties. | ||
Constraint:: |
public | function | Returns the name of the class that validates this constraint. | 1 |
Constraint:: |
public | function | Returns the value of a lazily initialized option. | |
Constraint:: |
public | function | Sets the value of a lazily initialized option. | |
Constraint:: |
public | function | Optimizes the serialized value to minimize storage space. |