[Validator] Deprecate validating DateTimeInterface in Date|Time|DateTime constraints
This commit is contained in:
parent
f2f4cd82c3
commit
5454e6fc1d
@ -162,3 +162,4 @@ Validator
|
|||||||
|
|
||||||
* The component is now decoupled from `symfony/translation` and uses `Symfony\Contracts\Translation\TranslatorInterface` instead
|
* The component is now decoupled from `symfony/translation` and uses `Symfony\Contracts\Translation\TranslatorInterface` instead
|
||||||
* The `ValidatorBuilderInterface` has been deprecated and `ValidatorBuilder` made final
|
* The `ValidatorBuilderInterface` has been deprecated and `ValidatorBuilder` made final
|
||||||
|
* Deprecated validating instances of `\DateTimeInterface` in `DateTimeValidator`, `DateValidator` and `TimeValidator`. Use `Type` instead or remove the constraint if the underlying model is type hinted to `\DateTimeInterface` already.
|
||||||
|
@ -163,6 +163,7 @@ Validator
|
|||||||
* Removed the `checkDNS` and `dnsMessage` options from the `Url` constraint.
|
* Removed the `checkDNS` and `dnsMessage` options from the `Url` constraint.
|
||||||
* The component is now decoupled from `symfony/translation` and uses `Symfony\Contracts\Translation\TranslatorInterface` instead
|
* The component is now decoupled from `symfony/translation` and uses `Symfony\Contracts\Translation\TranslatorInterface` instead
|
||||||
* The `ValidatorBuilderInterface` has been removed and `ValidatorBuilder` is now final
|
* The `ValidatorBuilderInterface` has been removed and `ValidatorBuilder` is now final
|
||||||
|
* Removed support for validating instances of `\DateTimeInterface` in `DateTimeValidator`, `DateValidator` and `TimeValidator`. Use `Type` instead or remove the constraint if the underlying model is type hinted to `\DateTimeInterface` already.
|
||||||
|
|
||||||
Workflow
|
Workflow
|
||||||
--------
|
--------
|
||||||
|
@ -8,6 +8,8 @@ CHANGELOG
|
|||||||
* decoupled from `symfony/translation` by using `Symfony\Contracts\Translation\TranslatorInterface`
|
* decoupled from `symfony/translation` by using `Symfony\Contracts\Translation\TranslatorInterface`
|
||||||
* deprecated `ValidatorBuilderInterface`
|
* deprecated `ValidatorBuilderInterface`
|
||||||
* made `ValidatorBuilder` final
|
* made `ValidatorBuilder` final
|
||||||
|
* marked `format` the default option in `DateTime` constraint
|
||||||
|
* deprecated validating instances of `\DateTimeInterface` in `DateTimeValidator`, `DateValidator` and `TimeValidator`.
|
||||||
|
|
||||||
4.1.0
|
4.1.0
|
||||||
-----
|
-----
|
||||||
|
@ -33,4 +33,9 @@ class DateTime extends Constraint
|
|||||||
|
|
||||||
public $format = 'Y-m-d H:i:s';
|
public $format = 'Y-m-d H:i:s';
|
||||||
public $message = 'This value is not a valid datetime.';
|
public $message = 'This value is not a valid datetime.';
|
||||||
|
|
||||||
|
public function getDefaultOption()
|
||||||
|
{
|
||||||
|
return 'format';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,13 @@ class DateTimeValidator extends DateValidator
|
|||||||
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\DateTime');
|
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\DateTime');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null === $value || '' === $value || $value instanceof \DateTimeInterface) {
|
if (null === $value || '' === $value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($value instanceof \DateTimeInterface) {
|
||||||
|
@trigger_error(sprintf('Validating a \\DateTimeInterface with "%s" is deprecated since version 4.2. Use "%s" instead or remove the constraint if the underlying model is already type hinted to \\DateTimeInterface.', DateTime::class, Type::class), E_USER_DEPRECATED);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,13 @@ class DateValidator extends ConstraintValidator
|
|||||||
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Date');
|
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Date');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null === $value || '' === $value || $value instanceof \DateTimeInterface) {
|
if (null === $value || '' === $value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($value instanceof \DateTimeInterface) {
|
||||||
|
@trigger_error(sprintf('Validating a \\DateTimeInterface with "%s" is deprecated since version 4.2. Use "%s" instead or remove the constraint if the underlying model is already type hinted to \\DateTimeInterface.', Date::class, Type::class), E_USER_DEPRECATED);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,13 @@ class TimeValidator extends ConstraintValidator
|
|||||||
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Time');
|
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Time');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null === $value || '' === $value || $value instanceof \DateTimeInterface) {
|
if (null === $value || '' === $value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($value instanceof \DateTimeInterface) {
|
||||||
|
@trigger_error(sprintf('Validating a \\DateTimeInterface with "%s" is deprecated since version 4.2. Use "%s" instead or remove the constraint if the underlying model is already type hinted to \\DateTimeInterface.', Time::class, Type::class), E_USER_DEPRECATED);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +36,10 @@ class DateTimeValidatorTest extends ConstraintValidatorTestCase
|
|||||||
$this->assertNoViolation();
|
$this->assertNoViolation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group legacy
|
||||||
|
* @expectedDeprecation Validating a \DateTimeInterface with "Symfony\Component\Validator\Constraints\DateTime" is deprecated since version 4.2. Use "Symfony\Component\Validator\Constraints\Type" instead or remove the constraint if the underlying model is already type hinted to \DateTimeInterface.
|
||||||
|
*/
|
||||||
public function testDateTimeClassIsValid()
|
public function testDateTimeClassIsValid()
|
||||||
{
|
{
|
||||||
$this->validator->validate(new \DateTime(), new DateTime());
|
$this->validator->validate(new \DateTime(), new DateTime());
|
||||||
@ -43,6 +47,10 @@ class DateTimeValidatorTest extends ConstraintValidatorTestCase
|
|||||||
$this->assertNoViolation();
|
$this->assertNoViolation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group legacy
|
||||||
|
* @expectedDeprecation Validating a \DateTimeInterface with "Symfony\Component\Validator\Constraints\DateTime" is deprecated since version 4.2. Use "Symfony\Component\Validator\Constraints\Type" instead or remove the constraint if the underlying model is already type hinted to \DateTimeInterface.
|
||||||
|
*/
|
||||||
public function testDateTimeImmutableClassIsValid()
|
public function testDateTimeImmutableClassIsValid()
|
||||||
{
|
{
|
||||||
$this->validator->validate(new \DateTimeImmutable(), new DateTime());
|
$this->validator->validate(new \DateTimeImmutable(), new DateTime());
|
||||||
|
@ -36,6 +36,10 @@ class DateValidatorTest extends ConstraintValidatorTestCase
|
|||||||
$this->assertNoViolation();
|
$this->assertNoViolation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group legacy
|
||||||
|
* @expectedDeprecation Validating a \DateTimeInterface with "Symfony\Component\Validator\Constraints\Date" is deprecated since version 4.2. Use "Symfony\Component\Validator\Constraints\Type" instead or remove the constraint if the underlying model is already type hinted to \DateTimeInterface.
|
||||||
|
*/
|
||||||
public function testDateTimeClassIsValid()
|
public function testDateTimeClassIsValid()
|
||||||
{
|
{
|
||||||
$this->validator->validate(new \DateTime(), new Date());
|
$this->validator->validate(new \DateTime(), new Date());
|
||||||
@ -43,6 +47,10 @@ class DateValidatorTest extends ConstraintValidatorTestCase
|
|||||||
$this->assertNoViolation();
|
$this->assertNoViolation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group legacy
|
||||||
|
* @expectedDeprecation Validating a \DateTimeInterface with "Symfony\Component\Validator\Constraints\Date" is deprecated since version 4.2. Use "Symfony\Component\Validator\Constraints\Type" instead or remove the constraint if the underlying model is already type hinted to \DateTimeInterface.
|
||||||
|
*/
|
||||||
public function testDateTimeImmutableClassIsValid()
|
public function testDateTimeImmutableClassIsValid()
|
||||||
{
|
{
|
||||||
$this->validator->validate(new \DateTimeImmutable(), new Date());
|
$this->validator->validate(new \DateTimeImmutable(), new Date());
|
||||||
|
@ -36,6 +36,10 @@ class TimeValidatorTest extends ConstraintValidatorTestCase
|
|||||||
$this->assertNoViolation();
|
$this->assertNoViolation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group legacy
|
||||||
|
* @expectedDeprecation Validating a \DateTimeInterface with "Symfony\Component\Validator\Constraints\Time" is deprecated since version 4.2. Use "Symfony\Component\Validator\Constraints\Type" instead or remove the constraint if the underlying model is already type hinted to \DateTimeInterface.
|
||||||
|
*/
|
||||||
public function testDateTimeClassIsValid()
|
public function testDateTimeClassIsValid()
|
||||||
{
|
{
|
||||||
$this->validator->validate(new \DateTime(), new Time());
|
$this->validator->validate(new \DateTime(), new Time());
|
||||||
@ -100,6 +104,10 @@ class TimeValidatorTest extends ConstraintValidatorTestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group legacy
|
||||||
|
* @expectedDeprecation Validating a \DateTimeInterface with "Symfony\Component\Validator\Constraints\Time" is deprecated since version 4.2. Use "Symfony\Component\Validator\Constraints\Type" instead or remove the constraint if the underlying model is already type hinted to \DateTimeInterface.
|
||||||
|
*/
|
||||||
public function testDateTimeImmutableIsValid()
|
public function testDateTimeImmutableIsValid()
|
||||||
{
|
{
|
||||||
$this->validator->validate(new \DateTimeImmutable(), new Time());
|
$this->validator->validate(new \DateTimeImmutable(), new Time());
|
||||||
|
Reference in New Issue
Block a user