8000 Rename option to stopOnFirst · symfony/symfony@8f36692 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8f36692

Browse files
committed
Rename option to stopOnFirst
1 parent 92baf9a commit 8f36692

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

src/Symfony/Component/Validator/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.3
5+
---
6+
7+
* Add the `stopOnFirstError` option to the `Unique` constraint
8+
49
7.2
510
---
611

src/Symfony/Component/Validator/Constraints/Unique.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Unique extends Constraint
2626

2727
public array|string $fields = [];
2828
public ?string $errorPath = null;
29-
public bool $multipleErrors = false;
29+
public bool $stopOnFirstError = true;
3030

3131
protected const ERROR_NAMES = [
3232
self::IS_NOT_UNIQUE => 'IS_NOT_UNIQUE',
@@ -49,15 +49,15 @@ public function __construct(
4949
mixed $payload = null,
5050
array|string|null $fields = null,
5151
?string $errorPath = null,
52-
?bool $multipleErrors = null,
52+
?bool $stopOnFirstError = null,
5353
) {
5454
parent::__construct($options, $groups, $payload);
5555

5656
$this->message = $message ?? $this->message;
5757
$this->normalizer = $normalizer ?? $this->normalizer;
5858
$this->fields = $fields ?? $this->fields;
5959
$this->errorPath = $errorPath ?? $this->errorPath;
60-
$this->multipleErrors = $multipleErrors ?? $this->multipleErrors;
60+
$this->stopOnFirstError = $stopOnFirstError ?? $this->stopOnFirstError;
6161

6262
if (null !== $this->normalizer && !\is_callable($this->normalizer)) {
6363
throw new InvalidArgumentException(\sprintf('The "normalizer" option must be a valid callable ("%s" given).', get_debug_type($this->normalizer)));

src/Symfony/Component/Validator/Constraints/UniqueValidator.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ public function validate(mixed $value, Constraint $constraint): void
5151
->setParameter('{{ value }}', $this->formatValue($element))
5252
->setCode(Unique::IS_NOT_UNIQUE);
5353

54-
if ($constraint->multipleErrors || null !== $constraint->errorPath) {
54+
if (!$constraint->stopOnFirstError || null !== $constraint->errorPath) {
5555
$violationBuilder->atPath("[$index]".(null !== $constraint->errorPath ? ".{$constraint->errorPath}" : ''));
5656
}
5757

5858
$violationBuilder->addViolation();
5959

60-
if (!$constraint->multipleErrors) {
60+
if ($constraint->stopOnFirstError) {
6161
return;
6262
}
6363
} else {

src/Symfony/Component/Validator/Tests/Constraints/UniqueValidatorTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,11 @@ public function testErrorPathWithNonList()
394394
->assertRaised();
395395
}
396396

397-
public function testMultiple()
397+
public function testWithoutStopOnFirstError()
398398
{
399399
$this->validator->validate(
400400
['a1', 'a2', 'a1', 'a1', 'a2'],
401-
new Unique(multipleErrors: true),
401+
new Unique(stopOnFirstError: false),
402402
);
403403

404404
$this
@@ -420,7 +420,7 @@ public function testMultiple()
420420
->assertRaised();
421421
}
422422

423-
public function testMultipleWithErrorPath()
423+
public function testWithoutStopOnFirstErrorWithErrorPath()
424424
{
425425
$array = [
426426
new DummyClassOne(),
@@ -442,7 +442,7 @@ public function testMultipleWithErrorPath()
442442
normalizer: [self::class, 'normalizeDummyClassOne'],
443443
fields: 'code',
444444
errorPath: 'code',
445-
multipleErrors: true,
445+
stopOnFirstError: false,
446446
)
447447
);
448448

0 commit comments

Comments
 (0)
0