Skip to content

Commit 67e15bf

Browse files
[Validator] Deprecate Constraint::$errorNames in favor of Constraint::ERROR_NAMES
1 parent 0c70f5c commit 67e15bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+89
-60
lines changed

UPGRADE-6.1.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ Serializer
1313
* Deprecate `ContextAwareDenormalizerInterface`, use `DenormalizerInterface` instead
1414
* Deprecate `ContextAwareEncoderInterface`, use `EncoderInterface` instead
1515
* Deprecate `ContextAwareDecoderInterface`, use `DecoderInterface` instead
16+
17+
Validator
18+
---------
19+
20+
* Deprecate `Constraint::$errorNames`, use `Constraint::ERROR_NAMES` instead

src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntity.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ class UniqueEntity extends Constraint
2626
{
2727
public const NOT_UNIQUE_ERROR = '23bd9dbf-6b9b-41cd-a99e-4844bcf3077f';
2828

29+
protected const ERROR_NAMES = [
30+
self::NOT_UNIQUE_ERROR => 'NOT_UNIQUE_ERROR',
31+
];
32+
2933
public $message = 'This value is already used.';
3034
public $service = 'doctrine.orm.validator.unique';
3135
public $em = null;
@@ -35,9 +39,10 @@ class UniqueEntity extends Constraint
3539
public $errorPath = null;
3640
public $ignoreNull = true;
3741

38-
protected static $errorNames = [
39-
self::NOT_UNIQUE_ERROR => 'NOT_UNIQUE_ERROR',
40-
];
42+
/**
43+
* @deprecated since Symfony 6.1, use protected const ERROR_NAMES instead
44+
*/
45+
protected static $errorNames = self::ERROR_NAMES;
4146

4247
/**
4348
* {@inheritdoc}

src/Symfony/Component/Form/Extension/Validator/Constraints/Form.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,16 @@ class Form extends Constraint
2121
public const NOT_SYNCHRONIZED_ERROR = '1dafa156-89e1-4736-b832-419c2e501fca';
2222
public const NO_SUCH_FIELD_ERROR = '6e5212ed-a197-4339-99aa-5654798a4854';
2323

24-
protected static $errorNames = [
24+
protected const ERROR_NAMES = [
2525
self::NOT_SYNCHRONIZED_ERROR => 'NOT_SYNCHRONIZED_ERROR',
2626
self::NO_SUCH_FIELD_ERROR => 'NO_SUCH_FIELD_ERROR',
2727
];
2828

29+
/**
30+
* @deprecated since Symfony 6.1, use protected const ERROR_NAMES instead
31+
*/
32+
protected static $errorNames = self::ERROR_NAMES;
33+
2934
/**
3035
* {@inheritdoc}
3136
*/

src/Symfony/Component/Validator/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
6.1
5+
---
6+
7+
* Deprecate `Constraint::$errorNames`, use `Constraint::ERROR_NAMES` instead
8+
49
6.0
510
---
611

src/Symfony/Component/Validator/Constraint.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ abstract class Constraint
4747
/**
4848
* Maps error codes to the names of their constants.
4949
*/
50+
protected const ERROR_NAMES = [];
51+
52+
/**
53+
* @deprecated since Symfony 6.1, use protected const ERROR_NAMES instead
54+
*/
5055
protected static $errorNames = [];
5156

5257
/**
@@ -70,6 +75,10 @@ abstract class Constraint
7075
*/
7176
public static function getErrorName(string $errorCode): string
7277
{
78+
if (isset(static::ERROR_NAMES[$errorCode])) {
79+
return static::ERROR_NAMES[$errorCode];
80+
}
81+
7382
if (!isset(static::$errorNames[$errorCode])) {
7483
throw new InvalidArgumentException(sprintf('The error code "%s" does not exist for constraint of type "%s".', $errorCode, static::class));
7584
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class AtLeastOneOf extends Composite
2222
{
2323
public const AT_LEAST_ONE_OF_ERROR = 'f27e6d6c-261a-4056-b391-6673a623531c';
2424

25-
protected static $errorNames = [
25+
protected const ERROR_NAMES = [
2626
self::AT_LEAST_ONE_OF_ERROR => 'AT_LEAST_ONE_OF_ERROR',
2727
];
2828

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Bic extends Constraint
3333
public const INVALID_CASE_ERROR = '11884038-3312-4ae5-9d04-699f782130c7';
3434
public const INVALID_IBAN_COUNTRY_CODE_ERROR = '29a2c3bb-587b-4996-b6f5-53081364cea5';
3535

36-
protected static $errorNames = [
36+
protected const ERROR_NAMES = [
3737
self::INVALID_LENGTH_ERROR => 'INVALID_LENGTH_ERROR',
3838
self::INVALID_CHARACTERS_ERROR => 'INVALID_CHARACTERS_ERROR',
3939
self::INVALID_BANK_CODE_ERROR => 'INVALID_BANK_CODE_ERROR',

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Blank extends Constraint
2424
{
2525
public const NOT_BLANK_ERROR = '183ad2de-533d-4796-a439-6d3c3852b549';
2626

27-
protected static $errorNames = [
27+
protected const ERROR_NAMES = [
2828
self::NOT_BLANK_ERROR => 'NOT_BLANK_ERROR',
2929
];
3030

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class CardScheme extends Constraint
4141
public const NOT_NUMERIC_ERROR = 'a2ad9231-e827-485f-8a1e-ef4d9a6d5c2e';
4242
public const INVALID_FORMAT_ERROR = 'a8faedbf-1c2f-4695-8d22-55783be8efed';
4343

44-
protected static $errorNames = [
44+
protected const ERROR_NAMES = [
4545
self::NOT_NUMERIC_ERROR => 'NOT_NUMERIC_ERROR',
4646
self::INVALID_FORMAT_ERROR => 'INVALID_FORMAT_ERROR',
4747
];

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Choice extends Constraint
2626
public const TOO_FEW_ERROR = '11edd7eb-5872-4b6e-9f12-89923999fd0e';
2727
public const TOO_MANY_ERROR = '9bd98e49-211c-433f-8630-fd1c2d0f08c3';
2828

29-
protected static $errorNames = [
29+
protected const ERROR_NAMES = [
3030
self::NO_SUCH_CHOICE_ERROR => 'NO_SUCH_CHOICE_ERROR',
3131
self::TOO_FEW_ERROR => 'TOO_FEW_ERROR',
3232
self::TOO_MANY_ERROR => 'TOO_MANY_ERROR',

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy