8000 [Validator] Deprecate `Constraint::$errorNames` in favor of `Constraint::ERROR_NAMES` by nicolas-grekas · Pull Request #45371 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Validator] Deprecate Constraint::$errorNames in favor of Constraint::ERROR_NAMES #45371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


8000
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions UPGRADE-6.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ Serializer
* Deprecate `ContextAwareDenormalizerInterface`, use `DenormalizerInterface` instead
* Deprecate `ContextAwareEncoderInterface`, use `EncoderInterface` instead
* Deprecate `ContextAwareDecoderInterface`, use `DecoderInterface` instead

Validator
---------

* Deprecate `Constraint::$errorNames`, use `Constraint::ERROR_NAMES` instead
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class UniqueEntity extends Constraint
{
public const NOT_UNIQUE_ERROR = '23bd9dbf-6b9b-41cd-a99e-4844bcf3077f';

protected const ERROR_NAMES = [
self::NOT_UNIQUE_ERROR => 'NOT_UNIQUE_ERROR',
];

public $message = 'This value is already used.';
public $service = 'doctrine.orm.validator.unique';
public $em = null;
Expand All @@ -35,9 +39,10 @@ class UniqueEntity extends Constraint
public $errorPath = null;
public $ignoreNull = true;

protected static $errorNames = [
self::NOT_UNIQUE_ERROR => 'NOT_UNIQUE_ERROR',
];
/**
* @deprecated since Symfony 6.1, use const ERROR_NAMES instead
*/
protected static $errorNames = self::ERROR_NAMES;

/**
* {@inheritdoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ class Form extends Constraint
public const NOT_SYNCHRONIZED_ERROR = '1dafa156-89e1-4736-b832-419c2e501fca';
public const NO_SUCH_FIELD_ERROR = '6e5212ed-a197-4339-99aa-5654798a4854';

protected static $errorNames = [
protected const ERROR_NAMES = [
self::NOT_SYNCHRONIZED_ERROR => 'NOT_SYNCHRONIZED_ERROR',
self::NO_SUCH_FIELD_ERROR => 'NO_SUCH_FIELD_ERROR',
];

/**
* @deprecated since Symfony 6.1, use const ERROR_NAMES instead
*/
protected static $errorNames = self::ERROR_NAMES;

/**
* {@inheritdoc}
*/
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Validator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

6.1
---

* Deprecate `Constraint::$errorNames`, use `Constraint::ERROR_NAMES` instead

6.0
---

Expand Down
11 changes: 11 additions & 0 deletions src/Symfony/Component/Validator/Constraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ abstract class Constraint
/**
* Maps error codes to the names of their constants.
*/
protected const ERROR_NAMES = [];

/**
* @deprecated since Symfony 6.1, use protected const ERROR_NAMES instead
*/
protected static $errorNames = [];

/**
Expand All @@ -70,10 +75,16 @@ abstract class Constraint
*/
public static function getErrorName(string $errorCode): string
{
if (isset(static::ERROR_NAMES[$errorCode])) {
return static::ERROR_NAMES[$errorCode];
}

if (!isset(static::$errorNames[$errorCode])) {
throw new InvalidArgumentException(sprintf('The error code "%s" does not exist for constraint of type "%s".', $errorCode, static::class));
}

trigger_deprecation('symfony/validator', '6.1', 'The "%s::$errorNames" property is deprecated, use protected const ERROR_NAMES instead.', static::class);

return static::$errorNames[$errorCode];
}

Expand Down
7 changes: 6 additions & 1 deletion src/Symfony/Component/Validator/Constraints/AtLeastOneOf.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ class AtLeastOneOf extends Composite
{
public const AT_LEAST_ONE_OF_ERROR = 'f27e6d6c-261a-4056-b391-6673a623531c';

protected static $errorNames = [
protected const ERROR_NAMES = [
self::AT_LEAST_ONE_OF_ERROR => 'AT_LEAST_ONE_OF_ERROR',
];

/**
* @deprecated since Symfony 6.1, use const ERROR_NAMES instead
*/
protected static $errorNames = self::ERROR_NAMES;

public $constraints = [];
public $message = 'This value should satisfy at least one of the following constraints:';
public $messageCollection = 'Each element of this collection should satisfy its own set of constraints.';
Expand Down
7 changes: 6 additions & 1 deletion src/Symfony/Component/Validator/Constraints/Bic.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,19 @@ class Bic extends Constraint
public const INVALID_CASE_ERROR = '11884038-3312-4ae5-9d04-699f782130c7';
public const INVALID_IBAN_COUNTRY_CODE_ERROR = '29a2c3bb-587b-4996-b6f5-53081364cea5';

protected static $errorNames = [
protected const ERROR_NAMES = [
self::INVALID_LENGTH_ERROR => 'INVALID_LENGTH_ERROR',
self::INVALID_CHARACTERS_ERROR => 'INVALID_CHARACTERS_ERROR',
self::INVALID_BANK_CODE_ERROR => 'INVALID_BANK_CODE_ERROR',
self::INVALID_COUNTRY_CODE_ERROR => 'INVALID_COUNTRY_CODE_ERROR',
self::INVALID_CASE_ERROR => 'INVALID_CASE_ERROR',
];

/**
* @deprecated since Symfony 6.1, use const ERROR_NAMES instead
*/
protected static $errorNames = self::ERROR_NAMES;

public $message = 'This is not a valid Business Identifier Code (BIC).';
public $ibanMessage = 'This Business Identifier Code (BIC) is not associated with IBAN {{ iban }}.';
public $iban;
Expand Down
7 changes: 6 additions & 1 deletion src/Symfony/Component/Validator/Constraints/Blank.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ class Blank extends Constraint
{
public const NOT_BLANK_ERROR = '183ad2de-533d-4796-a439-6d3c3852b549';

protected static $errorNames = [
protected const ERROR_NAMES = [
self::NOT_BLANK_ERROR => 'NOT_BLANK_ERROR',
];

/**
* @deprecated since Symfony 6.1, use const ERROR_NAMES instead
*/
protected static $errorNames = self::ERROR_NAMES;

public $message = 'This value should be blank.';

public function __construct(array $options = null, string $message = null, array $groups = null, mixed $payload = null)
Expand Down
7 changes: 6 additions & 1 deletion src/Symfony/Component/Validator/Constraints/CardScheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,16 @@ class CardScheme extends Constraint
public const NOT_NUMERIC_ERROR = 'a2ad9231-e827-485f-8a1e-ef4d9a6d5c2e';
public const INVALID_FORMAT_ERROR = 'a8faedbf-1c2f-4695-8d22-55783be8efed';

protected static $errorNames = [
protected const ERROR_NAMES = [
self::NOT_NUMERIC_ERROR => 'NOT_NUMERIC_ERROR',
self::INVALID_FORMAT_ERROR => 'INVALID_FORMAT_ERROR',
];

/**
* @deprecated since Symfony 6.1, use const ERROR_NAMES instead
*/
protected static $errorNames = self::ERROR_NAMES;

public $message = 'Unsupported card type or invalid card number.';
public $schemes;

Expand Down
7 changes: 6 additions & 1 deletion src/Symfony/Component/Validator/Constraints/Choice.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ class Choice extends Constraint
public const TOO_FEW_ERROR = '11edd7eb-5872-4b6e-9f12-89923999fd0e';
public const TOO_MANY_ERROR = '9bd98e49-211c-433f-8630-fd1c2d0f08c3';

protected static $errorNames = [
protected const ERROR_NAMES = [
self::NO_SUCH_CHOICE_ERROR => 'NO_SUCH_CHOICE_ERROR',
self::TOO_FEW_ERROR => 'TOO_FEW_ERROR',
self::TOO_MANY_ERROR => 'TOO_MANY_ERROR',
];

/**
* @deprecated since Symfony 6.1, use const ERROR_NAMES instead
*/
protected static $errorNames = self::ERROR_NAMES;

public $choices;
public $callback;
public $multiple = false;
Expand Down
7 changes: 6 additions & 1 deletion src/Symfony/Component/Validator/Constraints/Cidr.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Cidr extends Constraint
public const INVALID_CIDR_ERROR = '5649e53a-5afb-47c5-a360-ffbab3be8567';
public const OUT_OF_RANGE_ERROR = 'b9f14a51-acbd-401a-a078-8c6b204ab32f';

protected static $errorNames = [
protected const ERROR_NAMES = [
self::INVALID_CIDR_ERROR => 'INVALID_CIDR_ERROR',
self::OUT_OF_RANGE_ERROR => 'OUT_OF_RANGE_VIOLATION',
];
Expand All @@ -40,6 +40,11 @@ class Cidr extends Constraint
Ip::V6 => 128,
];

/**
* @deprecated since Symfony 6.1, use const ERROR_NAMES instead
*/
protected static $errorNames = self::ERROR_NAMES;

public $version = Ip::ALL;

public $message = 'This value is not a valid CIDR notation.';
Expand Down
7 changes: 6 additions & 1 deletion src/Symfony/Component/Validator/Constraints/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ class Collection extends Composite
public const MISSING_FIELD_ERROR = '2fa2158c-2a7f-484b-98aa-975522539ff8';
public const NO_SUCH_FIELD_ERROR = '7703c766-b5d5-4cef-ace7-ae0dd82304e9';

protected static $errorNames = [
protected const ERROR_NAMES = [
self::MISSING_FIELD_ERROR => 'MISSING_FIELD_ERROR',
self::NO_SUCH_FIELD_ERROR => 'NO_SUCH_FIELD_ERROR',
];

/**
* @deprecated since Symfony 6.1, use const ERROR_NAMES instead
*/
protected static $errorNames = self::ERROR_NAMES;

public $fields = [];
public $allowExtraFields = false;
public $allowMissingFields = false;
Expand Down
7 changes: 6 additions & 1 deletion src/Symfony/Component/Validator/Constraints/Count.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,18 @@ class Count extends Constraint
public const NOT_EQUAL_COUNT_ERROR = '9fe5d43f-3784-4ece-a0e1-473fc02dadbc';
public const NOT_DIVISIBLE_BY_ERROR = DivisibleBy::NOT_DIVISIBLE_BY;

protected static $errorNames = [
protected const ERROR_NAMES = [
self::TOO_FEW_ERROR => 'TOO_FEW_ERROR',
self::TOO_MANY_ERROR => 'TOO_MANY_ERROR',
self::NOT_EQUAL_COUNT_ERROR => 'NOT_EQUAL_COUNT_ERROR',
self::NOT_DIVISIBLE_BY_ERROR => 'NOT_DIVISIBLE_BY_ERROR',
];

/**
* @deprecated since Symfony 6.1, use const ERROR_NAMES instead
*/
protected static $errorNames = self::ERROR_NAMES;

public $minMessage = 'This collection should contain {{ limit }} element or more.|This collection should contain {{ limit }} elements or more.';
public $maxMessage = 'This collection should contain {{ limit }} element or less.|This collection should contain {{ limit }} elements or less.';
public $exactMessage = 'This collection should contain exactly {{ limit }} element.|This collection should contain exactly {{ limit }} elements.';
Expand Down
7 changes: 6 additions & 1 deletion src/Symfony/Component/Validator/Constraints/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ class Country extends Constraint
{
public const NO_SUCH_COUNTRY_ERROR = '8f900c12-61bd-455d-9398-996cd040f7f0';

protected static $errorNames = [
protected const ERROR_NAMES = [
self::NO_SUCH_COUNTRY_ERROR => 'NO_SUCH_COUNTRY_ERROR',
];

/**
* @deprecated since Symfony 6.1, use const ERROR_NAMES instead
*/
protected static $errorNames = self::ERROR_NAMES;

public $message = 'This value is not a valid country.';
public $alpha3 = false;

Expand Down
7 changes: 6 additions & 1 deletion src/Symfony/Component/Validator/Constraints/CssColor.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ class CssColor extends Constraint
public const HSLA = 'hsla';
public const INVALID_FORMAT_ERROR = '454ab47b-aacf-4059-8f26-184b2dc9d48d';

protected static $errorNames = [
protected const ERROR_NAMES = [
self::INVALID_FORMAT_ERROR => 'INVALID_FORMAT_ERROR',
];

/**
* @deprecated since Symfony 6.1, use const ERROR_NAMES instead
*/
protected static $errorNames = self::ERROR_NAMES;

/**
* @var string[]
*/
Expand Down
7 changes: 6 additions & 1 deletion src/Symfony/Component/Validator/Constraints/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ class Currency extends Constraint
{
public const NO_SUCH_CURRENCY_ERROR = '69945ac1-2db4-405f-bec7-d2772f73df52';

protected static $errorNames = [
protected const ERROR_NAMES = [
self::NO_SUCH_CURRENCY_ERROR => 'NO_SUCH_CURRENCY_ERROR',
];

/**
* @deprecated since Symfony 6.1, use const ERROR_NAMES instead
*/
protected static $errorNames = self::ERROR_NAMES;

public $message = 'This value is not a valid currency.';

public function __construct(array $options = null, string $message = null, array $groups = null, mixed $payload = null)
Expand Down
7 changes: 6 additions & 1 deletion src/Symfony/Component/Validator/Constraints/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ class Date extends Constraint
public const INVALID_FORMAT_ERROR = '69819696-02ac-4a99-9ff0-14e127c4d1bc';
public const INVALID_DATE_ERROR = '3c184ce5-b31d-4de7-8b76-326da7b2be93';

protected static $errorNames = [
protected const ERROR_NAMES = [
self::INVALID_FORMAT_ERROR => 'INVALID_FORMAT_ERROR',
self::INVALID_DATE_ERROR => 'INVALID_DATE_ERROR',
];

/**
* @deprecated since Symfony 6.1, use const ERROR_NAMES instead
*/
protected static $errorNames = self::ERROR_NAMES;

public $message = 'This value is not a valid date.';

public function __construct(array $options = null, string $message = null, array $groups = null, mixed $payload = null)
Expand Down
7 changes: 6 additions & 1 deletion src/Symfony/Component/Validator/Constraints/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ class DateTime extends Constraint
public const INVALID_DATE_ERROR = 'd52afa47-620d-4d99-9f08-f4d85b36e33c';
public const INVALID_TIME_ERROR = '5e797c9d-74f7-4098-baa3-94390c447b27';

protected static $errorNames = [
protected const ERROR_NAMES = [
self::INVALID_FORMAT_ERROR => 'INVALID_FORMAT_ERROR',
self::INVALID_DATE_ERROR => 'INVALID_DATE_ERROR',
self::INVALID_TIME_ERROR => 'INVALID_TIME_ERROR',
];

/**
* @deprecated since Symfony 6.1, use const ERROR_NAMES instead
*/
protected static $errorNames = self::ERROR_NAMES;

public $format = 'Y-m-d H:i:s';
public $message = 'This value is not a valid datetime.';

Expand Down
7 changes: 6 additions & 1 deletion src/Symfony/Component/Validator/Constraints/DivisibleBy.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ class DivisibleBy extends AbstractComparison
{
public const NOT_DIVISIBLE_BY = '6d99d6c3-1464-4ccf-bdc7-14d083cf455c';

protected static $errorNames = [
protected const ERROR_NAMES = [
self::NOT_DIVISIBLE_BY => 'NOT_DIVISIBLE_BY',
];

/**
* @deprecated since Symfony 6.1, use const ERROR_NAMES instead
*/
protected static $errorNames = self::ERROR_NAMES;

public $message = 'This value should be a multiple of {{ compared_value }}.';
}
7 changes: 6 additions & 1 deletion src/Symfony/Component/Validator/Constraints/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ class Email extends Constraint
self::VALIDATION_MODE_LOOSE,
];

protected static $errorNames = [
protected const ERROR_NAMES = [
self::INVALID_FORMAT_ERROR => 'STRICT_CHECK_FAILED_ERROR',
];

/**
* @deprecated since Symfony 6.1, use const ERROR_NAMES instead
*/
protected static $errorNames = self::ERROR_NAMES;

public $message = 'This value is not a valid email address.';
public $mode;
public $normalizer;
Expand Down
7 changes: 6 additions & 1 deletion src/Symfony/Component/Validator/Constraints/EqualTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ class EqualTo extends AbstractComparison
{
public const NOT_EQUAL_ERROR = '478618a7-95ba-473d-9101-cabd45e49115';

protected static $errorNames = [
protected const ERROR_NAMES = [
self::NOT_EQUAL_ERROR => 'NOT_EQUAL_ERROR',
];

/**
* @deprecated since Symfony 6.1, use const ERROR_NAMES instead
*/
protected static $errorNames = self::ERROR_NAMES;

public $message = 'This value should be equal to {{ compared_value }}.';
}
7 changes: 6 additions & 1 deletion src/Symfony/Component/Validator/Constraints/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ class Expression extends Constraint
{
public const EXPRESSION_FAILED_ERROR = '6b3befbc-2f01-4ddf-be21-b57898905284';

protected static $errorNames = [
protected const ERROR_NAMES = [
self::EXPRESSION_FAILED_ERROR => 'EXPRESSION_FAILED_ERROR',
];

/**
* @deprecated since Symfony 6.1, use const ERROR_NAMES instead
*/
protected static $errorNames = self::ERROR_NAMES;

public $message = 'This value is not valid.';
public $expression;
public $values = [];
Expand Down
Loading
0