Skip to content

Commit 2f893f1

Browse files
committed
error if the fields option is missing for the Collection constraint
1 parent bb88dce commit 2f893f1

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Constraints/Collection.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,20 @@ class Collection extends Composite
4545
#[HasNamedArguments]
4646
public function __construct(mixed $fields = null, ?array $groups = null, mixed $payload = null, ?bool $allowExtraFields = null, ?bool $allowMissingFields = null, ?string $extraFieldsMessage = null, ?string $missingFieldsMessage = null)
4747
{
48+
$options = $fields;
49+
4850
if (self::isFieldsOption($fields)) {
51+
$options = [];
52+
53+
if (null !== $fields) {
54+
$options['fields'] = $fields;
55+
}
4956
$fields = ['fields' => $fields];
5057
} else {
5158
trigger_deprecation('symfony/validator', '7.3', 'Passing an array of options to configure the "%s" constraint is deprecated, use named arguments instead.', static::class);
5259
}
5360

54-
parent::__construct($fields, $groups, $payload);
61+
parent::__construct($options, $groups, $payload);
5562

5663
$this->allowExtraFields = $allowExtraFields ?? $this->allowExtraFields;
5764
$this->allowMissingFields = $allowMissingFields ?? $this->allowMissingFields;
@@ -88,6 +95,10 @@ protected function getCompositeOption(): string
8895

8996
private static function isFieldsOption($options): bool
9097
{
98+
if (null === $options) {
99+
return true;
100+
}
101+
91102
if (!\is_array($options)) {
92103
return false;
93104
}

0 commit comments

Comments
 (0)