10000 [Validator] Remove deprecated code paths by nicolas-grekas · Pull Request #50857 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Validator] Remove deprecated code paths #50857

8000
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
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions UPGRADE-7.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ Validator
* Add methods `getConstraint()`, `getCause()` and `__toString()` to `ConstraintViolationInterface`
* Add method `__toString()` to `ConstraintViolationListInterface`
* Add method `disableTranslation()` to `ConstraintViolationBuilderInterface`
* Remove static property `$errorNames` from all constraints, use const `ERROR_NAMES` instead
* Remove `VALIDATION_MODE_LOOSE` from `Email` constraint, use `VALIDATION_MODE_HTML5` instead
* Remove constraint `ExpressionLanguageSyntax`, use `ExpressionSyntax` instead

VarDumper
---------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ class UniqueEntity extends Constraint
public $errorPath;
public $ignoreNull = true;

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

/**
* @param array|string $fields The combination of fields that must contain unique values or a set of options
* @param bool|array|string $ignoreNull The combination of fields that ignore null values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ class Form extends Constraint
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 function getTargets(): string|array
{
return self::CLASS_CONSTRAINT;
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/Validator/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ CHANGELOG
* Add methods `getConstraint()`, `getCause()` and `__toString()` to `ConstraintViolationInterface`
* Add method `__toString()` to `ConstraintViolationListInterface`
* Add method `disableTranslation()` to `ConstraintViolationBuilderInterface`
* Remove static property `$errorNames` from all constraints, use const `ERROR_NAMES` instead
* Remove `VALIDATION_MODE_LOOSE` from `Email` constraint, use `VALIDATION_MODE_HTML5` instead
* Remove constraint `ExpressionLanguageSyntax`, use `ExpressionSyntax` instead

6.4
---
Expand Down
13 changes: 1 addition & 12 deletions src/Symfony/Component/Validator/Constraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ abstract class Constraint
*/
protected const ERROR_NAMES = [];

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

/**
* Domain-specific data attached to a constraint.
*
Expand All @@ -79,13 +74,7 @@ public static function getErrorName(string $errorCode): string
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];
throw new InvalidArgumentException(sprintf('The error code "%s" does not exist for constraint of type "%s".', $errorCode, static::class));
}

/**
Expand Down
5 changes: 0 additions & 5 deletions src/Symfony/Component/Validator/Constraints/AtLeastOneOf.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ class AtLeastOneOf extends Composite
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
5 changes: 0 additions & 5 deletions src/Symfony/Component/Validator/Constraints/Bic.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ class Bic extends Constraint
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
5 changes: 0 additions & 5 deletions src/Symfony/Component/Validator/Constraints/Blank.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ class Blank extends Constraint
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
5 changes: 0 additions & 5 deletions src/Symfony/Component/Validator/Constraints/CardScheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ class CardScheme extends Constraint
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
5 changes: 0 additions & 5 deletions src/Symfony/Component/Validator/Constraints/Choice.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ class Choice extends Constraint
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
5 changes: 0 additions & 5 deletions src/Symfony/Component/Validator/Constraints/Cidr.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ 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
5 changes: 0 additions & 5 deletions src/Symfony/Component/Validator/Constraints/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ class Collection extends Composite
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
5 changes: 0 additions & 5 deletions src/Symfony/Component/Validator/Constraints/Count.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ class Count extends Constraint
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
5 changes: 0 additions & 5 deletions src/Symfony/Component/Validator/Constraints/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ class Country extends Constraint
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
5 changes: 0 additions & 5 deletions src/Symfony/Component/Validator/Constraints/CssColor.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ class CssColor extends Constraint
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
5 changes: 0 additions & 5 deletions src/Symfony/Component/Validator/Constraints/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ class Currency extends Constraint
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
5 changes: 0 additions & 5 deletions src/Symfony/Component/Validator/Constraints/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ class Date extends Constraint
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
5 changes: 0 additions & 5 deletions src/Symfony/Component/Validator/Constraints/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ class DateTime extends Constraint
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
5 changes: 0 additions & 5 deletions src/Symfony/Component/Validator/Constraints/DivisibleBy.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,5 @@ class DivisibleBy extends AbstractComparison
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 }}.';
}
14 changes: 0 additions & 14 deletions src/Symfony/Component/Validator/Constraints/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,19 @@ class Email extends Constraint
public const VALIDATION_MODE_HTML5_ALLOW_NO_TLD = 'html5-allow-no-tld';
public const VALIDATION_MODE_HTML5 = 'html5';
public const VALIDATION_MODE_STRICT = 'strict';
/**
* @deprecated since Symfony 6.2, use VALIDATION_MODE_HTML5 instead
*/
public const VALIDATION_MODE_LOOSE = 'loose';

public const INVALID_FORMAT_ERROR = 'bd79c0ab-ddba-46cc-a703-a7a4b08de310';

public const VALIDATION_MODES = [
self::VALIDATION_MODE_HTML5_ALLOW_NO_TLD,
self::VALIDATION_MODE_HTML5,
self::VALIDATION_MODE_STRICT,
self::VALIDATION_MODE_LOOSE,
];

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 All @@ -73,10 +63,6 @@ public function __construct(
$this->mode = $mode ?? $this->mode;
$this->normalizer = $normalizer ?? $this->normalizer;

if (self::VALIDATION_MODE_LOOSE === $this->mode) {
trigger_deprecation('symfony/validator', '6.2', 'The "%s" mode is deprecated. It will be removed in 7.0 and the default mode will be changed to "%s".', self::VALIDATION_MODE_LOOSE, self::VALIDATION_MODE_HTML5);
}

if (self::VALIDATION_MODE_STRICT === $this->mode && !class_exists(StrictEmailValidator::class)) {
throw new LogicException(sprintf('The "egulias/email-validator" component is required to use the "%s" constraint in strict mode. Try running "composer require egulias/email-validator".', __CLASS__));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,20 @@ class EmailValidator extends ConstraintValidator
{
private const PATTERN_HTML5_ALLOW_NO_TLD = '/^[a-zA-Z0-9.!#$%&\'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/';
private const PATTERN_HTML5 = '/^[a-zA-Z0-9.!#$%&\'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/';
private const PATTERN_LOOSE = '/^.+\@\S+\.\S+$/';

private const EMAIL_PATTERNS = [
Email::VALIDATION_MODE_LOOSE => self::PATTERN_LOOSE,
Email::VALIDATION_MODE_HTML5 => self::PATTERN_HTML5,
Email::VALIDATION_MODE_HTML5_ALLOW_NO_TLD => self::PATTERN_HTML5_ALLOW_NO_TLD,
];

private string $defaultMode;

public function __construct(string $defaultMode = Email::VALIDATION_MODE_LOOSE)
public function __construct(string $defaultMode = Email::VALIDATION_MODE_HTML5)
{
if (!\in_array($defaultMode, Email::VALIDATION_MODES, true)) {
throw new InvalidArgumentException('The "defaultMode" parameter value is not valid.');
}

if (Email::VALIDATION_MODE_LOOSE === $defaultMode) {
trigger_deprecation('symfony/validator', '6.2', 'The "%s" mode is deprecated. It will be removed in 7.0 and the default mode will be changed to "%s".', Email::VALIDATION_MODE_LOOSE, Email::VALIDATION_MODE_HTML5);
}

$this->defaultMode = $defaultMode;
}

Expand Down
5 changes: 0 additions & 5 deletions src/Symfony/Component/Validator/Constraints/EqualTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,5 @@ class EqualTo extends AbstractComparison
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 }}.';
}
5 changes: 0 additions & 5 deletions src/Symfony/Component/Validator/Constraints/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ class Expression extends Constraint
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

This file was deleted.

Loading
0