Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/validator/Constraints/Collection.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 1fec387a4317 |
children | af1871eacc83 |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
22 class Collection extends Composite | 22 class Collection extends Composite |
23 { | 23 { |
24 const MISSING_FIELD_ERROR = '2fa2158c-2a7f-484b-98aa-975522539ff8'; | 24 const MISSING_FIELD_ERROR = '2fa2158c-2a7f-484b-98aa-975522539ff8'; |
25 const NO_SUCH_FIELD_ERROR = '7703c766-b5d5-4cef-ace7-ae0dd82304e9'; | 25 const NO_SUCH_FIELD_ERROR = '7703c766-b5d5-4cef-ace7-ae0dd82304e9'; |
26 | 26 |
27 protected static $errorNames = array( | 27 protected static $errorNames = [ |
28 self::MISSING_FIELD_ERROR => 'MISSING_FIELD_ERROR', | 28 self::MISSING_FIELD_ERROR => 'MISSING_FIELD_ERROR', |
29 self::NO_SUCH_FIELD_ERROR => 'NO_SUCH_FIELD_ERROR', | 29 self::NO_SUCH_FIELD_ERROR => 'NO_SUCH_FIELD_ERROR', |
30 ); | 30 ]; |
31 | 31 |
32 public $fields = array(); | 32 public $fields = []; |
33 public $allowExtraFields = false; | 33 public $allowExtraFields = false; |
34 public $allowMissingFields = false; | 34 public $allowMissingFields = false; |
35 public $extraFieldsMessage = 'This field was not expected.'; | 35 public $extraFieldsMessage = 'This field was not expected.'; |
36 public $missingFieldsMessage = 'This field is missing.'; | 36 public $missingFieldsMessage = 'This field is missing.'; |
37 | 37 |
39 * {@inheritdoc} | 39 * {@inheritdoc} |
40 */ | 40 */ |
41 public function __construct($options = null) | 41 public function __construct($options = null) |
42 { | 42 { |
43 // no known options set? $options is the fields array | 43 // no known options set? $options is the fields array |
44 if (is_array($options) | 44 if (\is_array($options) |
45 && !array_intersect(array_keys($options), array('groups', 'fields', 'allowExtraFields', 'allowMissingFields', 'extraFieldsMessage', 'missingFieldsMessage'))) { | 45 && !array_intersect(array_keys($options), ['groups', 'fields', 'allowExtraFields', 'allowMissingFields', 'extraFieldsMessage', 'missingFieldsMessage'])) { |
46 $options = array('fields' => $options); | 46 $options = ['fields' => $options]; |
47 } | 47 } |
48 | 48 |
49 parent::__construct($options); | 49 parent::__construct($options); |
50 } | 50 } |
51 | 51 |
54 */ | 54 */ |
55 protected function initializeNestedConstraints() | 55 protected function initializeNestedConstraints() |
56 { | 56 { |
57 parent::initializeNestedConstraints(); | 57 parent::initializeNestedConstraints(); |
58 | 58 |
59 if (!is_array($this->fields)) { | 59 if (!\is_array($this->fields)) { |
60 throw new ConstraintDefinitionException(sprintf('The option "fields" is expected to be an array in constraint %s', __CLASS__)); | 60 throw new ConstraintDefinitionException(sprintf('The option "fields" is expected to be an array in constraint %s', __CLASS__)); |
61 } | 61 } |
62 | 62 |
63 foreach ($this->fields as $fieldName => $field) { | 63 foreach ($this->fields as $fieldName => $field) { |
64 // the XmlFileLoader and YamlFileLoader pass the field Optional | 64 // the XmlFileLoader and YamlFileLoader pass the field Optional |
65 // and Required constraint as an array with exactly one element | 65 // and Required constraint as an array with exactly one element |
66 if (is_array($field) && 1 == count($field)) { | 66 if (\is_array($field) && 1 == \count($field)) { |
67 $this->fields[$fieldName] = $field = $field[0]; | 67 $this->fields[$fieldName] = $field = $field[0]; |
68 } | 68 } |
69 | 69 |
70 if (!$field instanceof Optional && !$field instanceof Required) { | 70 if (!$field instanceof Optional && !$field instanceof Required) { |
71 $this->fields[$fieldName] = $field = new Required($field); | 71 $this->fields[$fieldName] = $field = new Required($field); |
73 } | 73 } |
74 } | 74 } |
75 | 75 |
76 public function getRequiredOptions() | 76 public function getRequiredOptions() |
77 { | 77 { |
78 return array('fields'); | 78 return ['fields']; |
79 } | 79 } |
80 | 80 |
81 protected function getCompositeOption() | 81 protected function getCompositeOption() |
82 { | 82 { |
83 return 'fields'; | 83 return 'fields'; |