Merge branch '2.8' into 3.4
* 2.8: [Validator] Added the missing constraints instance checks
This commit is contained in:
commit
654dc2209b
@ -13,6 +13,7 @@ namespace Symfony\Component\Validator\Constraints;
|
|||||||
|
|
||||||
use Symfony\Component\Validator\Constraint;
|
use Symfony\Component\Validator\Constraint;
|
||||||
use Symfony\Component\Validator\ConstraintValidator;
|
use Symfony\Component\Validator\ConstraintValidator;
|
||||||
|
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Michael Hirschler <michael.vhirsch@gmail.com>
|
* @author Michael Hirschler <michael.vhirsch@gmail.com>
|
||||||
@ -26,6 +27,10 @@ class BicValidator extends ConstraintValidator
|
|||||||
*/
|
*/
|
||||||
public function validate($value, Constraint $constraint)
|
public function validate($value, Constraint $constraint)
|
||||||
{
|
{
|
||||||
|
if (!$constraint instanceof Bic) {
|
||||||
|
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Bic');
|
||||||
|
}
|
||||||
|
|
||||||
if (null === $value || '' === $value) {
|
if (null === $value || '' === $value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,10 @@ class CountValidator extends ConstraintValidator
|
|||||||
*/
|
*/
|
||||||
public function validate($value, Constraint $constraint)
|
public function validate($value, Constraint $constraint)
|
||||||
{
|
{
|
||||||
|
if (!$constraint instanceof Count) {
|
||||||
|
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Count');
|
||||||
|
}
|
||||||
|
|
||||||
if (null === $value) {
|
if (null === $value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -66,14 +66,14 @@ class UuidValidator extends ConstraintValidator
|
|||||||
*/
|
*/
|
||||||
public function validate($value, Constraint $constraint)
|
public function validate($value, Constraint $constraint)
|
||||||
{
|
{
|
||||||
if (null === $value || '' === $value) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$constraint instanceof Uuid) {
|
if (!$constraint instanceof Uuid) {
|
||||||
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Uuid');
|
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Uuid');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (null === $value || '' === $value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
|
if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
|
||||||
throw new UnexpectedTypeException($value, 'string');
|
throw new UnexpectedTypeException($value, 'string');
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user