Skip to content

Commit f0f744c

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: [Serializer] Save missing arguments in MissingConstructorArgumentsException remove support for deprecated "threadKey" parameter Remove useless comment in test [DomCrawler] Added Crawler::innerText() method [Form] Add the EnumType Fix iterrator in ServiceConfigurator [Console] Add support of RGB functional notation for output colors Add Slovak lang translation #41081 [Validator] Add error's uid to `Count` and `Length` constraints with "exactly" option enabled [Validator] Add missing thai translation [Yaml] Add 0 to float repr [Translation] Add Burmese translation [Notifier] Update FirebaseTransport.php fix: #43086 remove shortcut e for option exclude of Yaml/LintCommand - solve conflict with --env -e Map `multipart/form-data` as `form` Content-Type [Serializer] Throw NotNormalizableValueException when type is not known or not in body in discriminator map [Yaml] Use more concise float representation in dump [FrameworkBundle] Remove translation data_collector BEFORE adding it to profiler
2 parents 6e10a08 + 2bd2fdb commit f0f744c

File tree

10 files changed

+432
-16
lines changed

10 files changed

+432
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ CHANGELOG
1313
---
1414

1515
* Add support for `ConstraintViolationList::createFromMessage()`
16+
* Add error's uid to `Count` and `Length` constraints with "exactly" option enabled
1617

1718
5.3
1819
---

Constraints/Count.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ class Count extends Constraint
2525
{
2626
public const TOO_FEW_ERROR = 'bef8e338-6ae5-4caf-b8e2-50e7b0579e69';
2727
public const TOO_MANY_ERROR = '756b1212-697c-468d-a9ad-50dd783bb169';
28+
public const NOT_EQUAL_COUNT_ERROR = '9fe5d43f-3784-4ece-a0e1-473fc02dadbc';
2829
public const NOT_DIVISIBLE_BY_ERROR = DivisibleBy::NOT_DIVISIBLE_BY;
2930

3031
protected static $errorNames = [
3132
self::TOO_FEW_ERROR => 'TOO_FEW_ERROR',
3233
self::TOO_MANY_ERROR => 'TOO_MANY_ERROR',
34+
self::NOT_EQUAL_COUNT_ERROR => 'NOT_EQUAL_COUNT_ERROR',
3335
self::NOT_DIVISIBLE_BY_ERROR => 'NOT_DIVISIBLE_BY_ERROR',
3436
];
3537

Constraints/CountValidator.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,28 @@ public function validate(mixed $value, Constraint $constraint)
4141
$count = \count($value);
4242

4343
if (null !== $constraint->max && $count > $constraint->max) {
44-
$this->context->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->maxMessage)
44+
$exactlyOptionEnabled = $constraint->min == $constraint->max;
45+
46+
$this->context->buildViolation($exactlyOptionEnabled ? $constraint->exactMessage : $constraint->maxMessage)
4547
->setParameter('{{ count }}', $count)
4648
->setParameter('{{ limit }}', $constraint->max)
4749
->setInvalidValue($value)
4850
->setPlural((int) $constraint->max)
49-
->setCode(Count::TOO_MANY_ERROR)
51+
->setCode($exactlyOptionEnabled ? Count::NOT_EQUAL_COUNT_ERROR : Count::TOO_MANY_ERROR)
5052
->addViolation();
5153

5254
return;
5355
}
5456

5557
if (null !== $constraint->min && $count < $constraint->min) {
56-
$this->context->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->minMessage)
58+
$exactlyOptionEnabled = $constraint->min == $constraint->max;
59+
60+
$this->context->buildViolation($exactlyOptionEnabled ? $constraint->exactMessage : $constraint->minMessage)
5761
->setParameter('{{ count }}', $count)
5862
->setParameter('{{ limit }}', $constraint->min)
5963
->setInvalidValue($value)
6064
->setPlural((int) $constraint->min)
61-
->setCode(Count::TOO_FEW_ERROR)
65+
->setCode($exactlyOptionEnabled ? Count::NOT_EQUAL_COUNT_ERROR : Count::TOO_FEW_ERROR)
6266
->addViolation();
6367

6468
return;

Constraints/Length.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ class Length extends Constraint
2626
{
2727
public const TOO_SHORT_ERROR = '9ff3fdc4-b214-49db-8718-39c315e33d45';
2828
public const TOO_LONG_ERROR = 'd94b19cc-114f-4f44-9cc4-4138e80a87b9';
29+
public const NOT_EQUAL_LENGTH_ERROR = '4b6f5c76-22b4-409d-af16-fbe823ba9332';
2930
public const INVALID_CHARACTERS_ERROR = '35e6a710-aa2e-4719-b58e-24b35749b767';
3031

3132
protected static $errorNames = [
3233
self::TOO_SHORT_ERROR => 'TOO_SHORT_ERROR',
3334
self::TOO_LONG_ERROR => 'TOO_LONG_ERROR',
35+
self::NOT_EQUAL_LENGTH_ERROR => 'NOT_EQUAL_LENGTH_ERROR',
3436
self::INVALID_CHARACTERS_ERROR => 'INVALID_CHARACTERS_ERROR',
3537
];
3638

Constraints/LengthValidator.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,24 +68,28 @@ public function validate(mixed $value, Constraint $constraint)
6868
$length = mb_strlen($stringValue, $constraint->charset);
6969

7070
if (null !== $constraint->max && $length > $constraint->max) {
71-
$this->context->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->maxMessage)
71+
$exactlyOptionEnabled = $constraint->min == $constraint->max;
72+
73+
$this->context->buildViolation($exactlyOptionEnabled ? $constraint->exactMessage : $constraint->maxMessage)
7274
->setParameter('{{ value }}', $this->formatValue($stringValue))
7375
->setParameter('{{ limit }}', $constraint->max)
7476
->setInvalidValue($value)
7577
->setPlural((int) $constraint->max)
76-
->setCode(Length::TOO_LONG_ERROR)
78+
->setCode($exactlyOptionEnabled ? Length::NOT_EQUAL_LENGTH_ERROR : Length::TOO_LONG_ERROR)
7779
->addViolation();
7880

7981
return;
8082
}
8183

8284
if (null !== $constraint->min && $length < $constraint->min) {
83-
$this->context->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->minMessage)
85+
$exactlyOptionEnabled = $constraint->min == $constraint->max;
86+
87+
$this->context->buildViolation($exactlyOptionEnabled ? $constraint->exactMessage : $constraint->minMessage)
8488
->setParameter('{{ value }}', $this->formatValue($stringValue))
8589
->setParameter('{{ limit }}', $constraint->min)
8690
->setInvalidValue($value)
8791
->setPlural((int) $constraint->min)
88-
->setCode(Length::TOO_SHORT_ERROR)
92+
->setCode($exactlyOptionEnabled ? Length::NOT_EQUAL_LENGTH_ERROR : Length::TOO_SHORT_ERROR)
8993
->addViolation();
9094
}
9195
}

0 commit comments

Comments
 (0)