diff --git a/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php b/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php index 308d883b2e067..54e667972df4a 100644 --- a/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php +++ b/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php @@ -46,6 +46,10 @@ public function __construct(ManagerRegistry $registry) */ public function validate($entity, Constraint $constraint) { + if (!$constraint instanceof UniqueEntity) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\UniqueEntity'); + } + if (!is_array($constraint->fields) && !is_string($constraint->fields)) { throw new UnexpectedTypeException($constraint->fields, 'array'); } diff --git a/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php b/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php index 0df176f7d711f..b03e4ee66b58a 100644 --- a/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php +++ b/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php @@ -15,6 +15,7 @@ use Symfony\Component\Form\Extension\Validator\Util\ServerParams; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; /** * @author Bernhard Schussek @@ -42,6 +43,10 @@ public function __construct(ServerParams $params = null) */ public function validate($form, Constraint $constraint) { + if (!$constraint instanceof Form) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Form'); + } + if (!$form instanceof FormInterface) { return; } diff --git a/src/Symfony/Component/Security/Core/Validator/Constraints/UserPasswordValidator.php b/src/Symfony/Component/Security/Core/Validator/Constraints/UserPasswordValidator.php index ab455f3e9ed54..5f9ad2a9f24a9 100644 --- a/src/Symfony/Component/Security/Core/Validator/Constraints/UserPasswordValidator.php +++ b/src/Symfony/Component/Security/Core/Validator/Constraints/UserPasswordValidator.php @@ -17,6 +17,7 @@ use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; use Symfony\Component\Validator\Exception\ConstraintDefinitionException; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; class UserPasswordValidator extends ConstraintValidator { @@ -34,6 +35,10 @@ public function __construct(SecurityContextInterface $securityContext, EncoderFa */ public function validate($password, Constraint $constraint) { + if (!$constraint instanceof UserPassword) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\UserPassword'); + } + $user = $this->securityContext->getToken()->getUser(); if (!$user instanceof UserInterface) { diff --git a/src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php b/src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php index d5f904bab9f10..0e636aa930bf0 100644 --- a/src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php +++ b/src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php @@ -13,6 +13,7 @@ use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; /** * Provides a base class for the validation of property comparisons. @@ -26,6 +27,10 @@ abstract class AbstractComparisonValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof AbstractComparison) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\AbstractComparison'); + } + if (null === $value) { return; } diff --git a/src/Symfony/Component/Validator/Constraints/AllValidator.php b/src/Symfony/Component/Validator/Constraints/AllValidator.php index c38f19a6669c0..f9404ab41baa6 100644 --- a/src/Symfony/Component/Validator/Constraints/AllValidator.php +++ b/src/Symfony/Component/Validator/Constraints/AllValidator.php @@ -27,6 +27,10 @@ class AllValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof All) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\All'); + } + if (null === $value) { return; } diff --git a/src/Symfony/Component/Validator/Constraints/BlankValidator.php b/src/Symfony/Component/Validator/Constraints/BlankValidator.php index 0a673588fc0f6..fa84454d1031d 100644 --- a/src/Symfony/Component/Validator/Constraints/BlankValidator.php +++ b/src/Symfony/Component/Validator/Constraints/BlankValidator.php @@ -13,6 +13,7 @@ use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; /** * @author Bernhard Schussek @@ -26,6 +27,10 @@ class BlankValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof Blank) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Blank'); + } + if ('' !== $value && null !== $value) { $this->context->addViolation($constraint->message, array('{{ value }}' => $value)); } diff --git a/src/Symfony/Component/Validator/Constraints/CallbackValidator.php b/src/Symfony/Component/Validator/Constraints/CallbackValidator.php index 28b34250af6fc..39da982bb13ca 100644 --- a/src/Symfony/Component/Validator/Constraints/CallbackValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CallbackValidator.php @@ -30,6 +30,10 @@ class CallbackValidator extends ConstraintValidator */ public function validate($object, Constraint $constraint) { + if (!$constraint instanceof Callback) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Callback'); + } + if (null === $object) { return; } diff --git a/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php b/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php index 1ece3fdd65275..e38d814024a88 100644 --- a/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php @@ -13,6 +13,7 @@ use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; /** * Validates that a card number belongs to a specified scheme. @@ -103,6 +104,10 @@ class CardSchemeValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof CardScheme) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\CardScheme'); + } + if (null === $value || '' === $value) { return; } diff --git a/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php b/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php index 294e7dbfc931f..4309429a5e71c 100644 --- a/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php +++ b/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php @@ -32,6 +32,10 @@ class ChoiceValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof Choice) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Choice'); + } + if (!$constraint->choices && !$constraint->callback) { throw new ConstraintDefinitionException('Either "choices" or "callback" must be specified on constraint Choice'); } diff --git a/src/Symfony/Component/Validator/Constraints/CollectionValidator.php b/src/Symfony/Component/Validator/Constraints/CollectionValidator.php index f273ac40b95e5..b8b23f376dfa7 100644 --- a/src/Symfony/Component/Validator/Constraints/CollectionValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CollectionValidator.php @@ -27,6 +27,10 @@ class CollectionValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof Collection) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Collection'); + } + if (null === $value) { return; } diff --git a/src/Symfony/Component/Validator/Constraints/CountryValidator.php b/src/Symfony/Component/Validator/Constraints/CountryValidator.php index 1b3f8653e4ad6..0c883828f1e1a 100644 --- a/src/Symfony/Component/Validator/Constraints/CountryValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CountryValidator.php @@ -30,6 +30,10 @@ class CountryValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof Country) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Country'); + } + if (null === $value || '' === $value) { return; } diff --git a/src/Symfony/Component/Validator/Constraints/CurrencyValidator.php b/src/Symfony/Component/Validator/Constraints/CurrencyValidator.php index 4465e46dfeecf..050136be75b06 100644 --- a/src/Symfony/Component/Validator/Constraints/CurrencyValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CurrencyValidator.php @@ -30,6 +30,10 @@ class CurrencyValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof Currency) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Currency'); + } + if (null === $value || '' === $value) { return; } diff --git a/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php b/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php index 49e04b94f2bd8..270ff428d2f1f 100644 --- a/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php @@ -11,6 +11,9 @@ namespace Symfony\Component\Validator\Constraints; +use Symfony\Component\Validator\Constraint; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; + /** * @author Bernhard Schussek * @@ -19,4 +22,28 @@ class DateTimeValidator extends DateValidator { const PATTERN = '/^(\d{4})-(\d{2})-(\d{2}) (0[0-9]|1[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/'; + + /** + * {@inheritDoc} + */ + public function validate($value, Constraint $constraint) + { + if (!$constraint instanceof DateTime) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\DateTime'); + } + + if (null === $value || '' === $value || $value instanceof \DateTime) { + return; + } + + if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) { + throw new UnexpectedTypeException($value, 'string'); + } + + $value = (string) $value; + + if (!preg_match(static::PATTERN, $value, $matches) || !checkdate($matches[2], $matches[3], $matches[1])) { + $this->context->addViolation($constraint->message, array('{{ value }}' => $value)); + } + } } diff --git a/src/Symfony/Component/Validator/Constraints/DateValidator.php b/src/Symfony/Component/Validator/Constraints/DateValidator.php index f891f9d621a9b..19189248cfd64 100644 --- a/src/Symfony/Component/Validator/Constraints/DateValidator.php +++ b/src/Symfony/Component/Validator/Constraints/DateValidator.php @@ -29,6 +29,10 @@ class DateValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof Date) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Date'); + } + if (null === $value || '' === $value || $value instanceof \DateTime) { return; } diff --git a/src/Symfony/Component/Validator/Constraints/EmailValidator.php b/src/Symfony/Component/Validator/Constraints/EmailValidator.php index e0593102bc599..1e9b94552b7a7 100644 --- a/src/Symfony/Component/Validator/Constraints/EmailValidator.php +++ b/src/Symfony/Component/Validator/Constraints/EmailValidator.php @@ -27,6 +27,10 @@ class EmailValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof Email) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Email'); + } + if (null === $value || '' === $value) { return; } diff --git a/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php b/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php index e27859b08c19c..8323e5f6dbad6 100644 --- a/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php +++ b/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php @@ -17,6 +17,7 @@ use Symfony\Component\Validator\ConstraintValidator; use Symfony\Component\ExpressionLanguage\ExpressionLanguage; use Symfony\Component\Validator\Exception\RuntimeException; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; /** * @author Fabien Potencier @@ -44,6 +45,10 @@ public function __construct(PropertyAccessorInterface $propertyAccessor) */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof Expression) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Expression'); + } + if (null === $value || '' === $value) { return; } diff --git a/src/Symfony/Component/Validator/Constraints/FalseValidator.php b/src/Symfony/Component/Validator/Constraints/FalseValidator.php index 7cead615080a8..c257b84c5b0e5 100644 --- a/src/Symfony/Component/Validator/Constraints/FalseValidator.php +++ b/src/Symfony/Component/Validator/Constraints/FalseValidator.php @@ -13,6 +13,7 @@ use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; /** * @author Bernhard Schussek @@ -26,6 +27,10 @@ class FalseValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof False) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\False'); + } + if (null === $value || false === $value || 0 === $value || '0' === $value) { return; } diff --git a/src/Symfony/Component/Validator/Constraints/FileValidator.php b/src/Symfony/Component/Validator/Constraints/FileValidator.php index 06e16ebe2ca68..54f0b45d60dae 100644 --- a/src/Symfony/Component/Validator/Constraints/FileValidator.php +++ b/src/Symfony/Component/Validator/Constraints/FileValidator.php @@ -30,6 +30,10 @@ class FileValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof File) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\File'); + } + if (null === $value || '' === $value) { return; } diff --git a/src/Symfony/Component/Validator/Constraints/IbanValidator.php b/src/Symfony/Component/Validator/Constraints/IbanValidator.php index 3ec4c6ea7a79a..c6c5966685b98 100644 --- a/src/Symfony/Component/Validator/Constraints/IbanValidator.php +++ b/src/Symfony/Component/Validator/Constraints/IbanValidator.php @@ -13,6 +13,7 @@ use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; /** * @author Manuel Reinhard @@ -26,6 +27,10 @@ class IbanValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof Iban) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Iban'); + } + if (null === $value || '' === $value) { return; } diff --git a/src/Symfony/Component/Validator/Constraints/ImageValidator.php b/src/Symfony/Component/Validator/Constraints/ImageValidator.php index 76ce8767fcea8..414332b8603f9 100644 --- a/src/Symfony/Component/Validator/Constraints/ImageValidator.php +++ b/src/Symfony/Component/Validator/Constraints/ImageValidator.php @@ -13,6 +13,7 @@ use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Exception\ConstraintDefinitionException; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; /** * Validates whether a value is a valid image file and is valid @@ -27,6 +28,10 @@ class ImageValidator extends FileValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof Image) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Image'); + } + $violations = count($this->context->getViolations()); parent::validate($value, $constraint); diff --git a/src/Symfony/Component/Validator/Constraints/IpValidator.php b/src/Symfony/Component/Validator/Constraints/IpValidator.php index 3358ec25c4d81..8a53cfd7ce48d 100644 --- a/src/Symfony/Component/Validator/Constraints/IpValidator.php +++ b/src/Symfony/Component/Validator/Constraints/IpValidator.php @@ -30,6 +30,10 @@ class IpValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof Ip) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Ip'); + } + if (null === $value || '' === $value) { return; } diff --git a/src/Symfony/Component/Validator/Constraints/IsbnValidator.php b/src/Symfony/Component/Validator/Constraints/IsbnValidator.php index 62a3b0388e3b6..00e2c5dc1b720 100644 --- a/src/Symfony/Component/Validator/Constraints/IsbnValidator.php +++ b/src/Symfony/Component/Validator/Constraints/IsbnValidator.php @@ -29,6 +29,10 @@ class IsbnValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof Isbn) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Isbn'); + } + if (null === $value || '' === $value) { return; } diff --git a/src/Symfony/Component/Validator/Constraints/IssnValidator.php b/src/Symfony/Component/Validator/Constraints/IssnValidator.php index 7e0baa876dceb..fa8d9bacf2757 100644 --- a/src/Symfony/Component/Validator/Constraints/IssnValidator.php +++ b/src/Symfony/Component/Validator/Constraints/IssnValidator.php @@ -29,6 +29,10 @@ class IssnValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof Issn) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Issn'); + } + if (null === $value || '' === $value) { return; } diff --git a/src/Symfony/Component/Validator/Constraints/LanguageValidator.php b/src/Symfony/Component/Validator/Constraints/LanguageValidator.php index 5c4dbed2980f5..17c5cd75c160c 100644 --- a/src/Symfony/Component/Validator/Constraints/LanguageValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LanguageValidator.php @@ -30,6 +30,10 @@ class LanguageValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof Language) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Language'); + } + if (null === $value || '' === $value) { return; } diff --git a/src/Symfony/Component/Validator/Constraints/LengthValidator.php b/src/Symfony/Component/Validator/Constraints/LengthValidator.php index 8090a2c6a8aa6..2e8253b88e960 100644 --- a/src/Symfony/Component/Validator/Constraints/LengthValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LengthValidator.php @@ -25,6 +25,10 @@ class LengthValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof Length) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Length'); + } + if (null === $value || '' === $value) { return; } diff --git a/src/Symfony/Component/Validator/Constraints/LocaleValidator.php b/src/Symfony/Component/Validator/Constraints/LocaleValidator.php index 97c6aed97733a..eaab51a8bd57e 100644 --- a/src/Symfony/Component/Validator/Constraints/LocaleValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LocaleValidator.php @@ -30,6 +30,10 @@ class LocaleValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof Locale) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Locale'); + } + if (null === $value || '' === $value) { return; } diff --git a/src/Symfony/Component/Validator/Constraints/LuhnValidator.php b/src/Symfony/Component/Validator/Constraints/LuhnValidator.php index d3802fe99ae11..2823b4f3a15e8 100644 --- a/src/Symfony/Component/Validator/Constraints/LuhnValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LuhnValidator.php @@ -35,6 +35,10 @@ class LuhnValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof Luhn) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Luhn'); + } + if (null === $value || '' === $value) { return; } diff --git a/src/Symfony/Component/Validator/Constraints/NotBlankValidator.php b/src/Symfony/Component/Validator/Constraints/NotBlankValidator.php index dd3dbdd8498a1..84dcfe129ca7e 100644 --- a/src/Symfony/Component/Validator/Constraints/NotBlankValidator.php +++ b/src/Symfony/Component/Validator/Constraints/NotBlankValidator.php @@ -13,6 +13,7 @@ use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; /** * @author Bernhard Schussek @@ -26,6 +27,10 @@ class NotBlankValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof NotBlank) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\NotBlank'); + } + if (false === $value || (empty($value) && '0' != $value)) { $this->context->addViolation($constraint->message); } diff --git a/src/Symfony/Component/Validator/Constraints/NotNullValidator.php b/src/Symfony/Component/Validator/Constraints/NotNullValidator.php index 4ee65928ef0e0..8e0817b216e51 100644 --- a/src/Symfony/Component/Validator/Constraints/NotNullValidator.php +++ b/src/Symfony/Component/Validator/Constraints/NotNullValidator.php @@ -13,6 +13,7 @@ use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; /** * @author Bernhard Schussek @@ -26,6 +27,10 @@ class NotNullValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof NotNull) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\NotNull'); + } + if (null === $value) { $this->context->addViolation($constraint->message); } diff --git a/src/Symfony/Component/Validator/Constraints/NullValidator.php b/src/Symfony/Component/Validator/Constraints/NullValidator.php index 9753f43315f37..8ba248b1a7127 100644 --- a/src/Symfony/Component/Validator/Constraints/NullValidator.php +++ b/src/Symfony/Component/Validator/Constraints/NullValidator.php @@ -13,6 +13,7 @@ use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; /** * @author Bernhard Schussek @@ -26,6 +27,10 @@ class NullValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof Null) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Null'); + } + if (null !== $value) { if (is_object($value)) { $value = get_class($value); diff --git a/src/Symfony/Component/Validator/Constraints/RangeValidator.php b/src/Symfony/Component/Validator/Constraints/RangeValidator.php index 1a8ba15ac35ee..a16eb016fb09e 100644 --- a/src/Symfony/Component/Validator/Constraints/RangeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/RangeValidator.php @@ -13,6 +13,7 @@ use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; /** * @author Bernhard Schussek @@ -24,6 +25,10 @@ class RangeValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof Range) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Range'); + } + if (null === $value) { return; } diff --git a/src/Symfony/Component/Validator/Constraints/RegexValidator.php b/src/Symfony/Component/Validator/Constraints/RegexValidator.php index c39869d2882b5..aede23da12adb 100644 --- a/src/Symfony/Component/Validator/Constraints/RegexValidator.php +++ b/src/Symfony/Component/Validator/Constraints/RegexValidator.php @@ -30,6 +30,10 @@ class RegexValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof Regex) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Regex'); + } + if (null === $value || '' === $value) { return; } diff --git a/src/Symfony/Component/Validator/Constraints/TimeValidator.php b/src/Symfony/Component/Validator/Constraints/TimeValidator.php index 31259cc4b3773..9660f347d566f 100644 --- a/src/Symfony/Component/Validator/Constraints/TimeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/TimeValidator.php @@ -29,6 +29,10 @@ class TimeValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof Time) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Time'); + } + if (null === $value || '' === $value || $value instanceof \DateTime) { return; } diff --git a/src/Symfony/Component/Validator/Constraints/TrueValidator.php b/src/Symfony/Component/Validator/Constraints/TrueValidator.php index 2fbe0478ce1f0..f169c16fd2548 100644 --- a/src/Symfony/Component/Validator/Constraints/TrueValidator.php +++ b/src/Symfony/Component/Validator/Constraints/TrueValidator.php @@ -13,6 +13,7 @@ use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; /** * @author Bernhard Schussek @@ -26,6 +27,10 @@ class TrueValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof True) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\True'); + } + if (null === $value) { return; } diff --git a/src/Symfony/Component/Validator/Constraints/TypeValidator.php b/src/Symfony/Component/Validator/Constraints/TypeValidator.php index ecc88dfbd16d1..f042a9adef7a8 100644 --- a/src/Symfony/Component/Validator/Constraints/TypeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/TypeValidator.php @@ -13,6 +13,7 @@ use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; /** * @author Bernhard Schussek @@ -26,6 +27,10 @@ class TypeValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof Type) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Type'); + } + if (null === $value) { return; } diff --git a/src/Symfony/Component/Validator/Constraints/UrlValidator.php b/src/Symfony/Component/Validator/Constraints/UrlValidator.php index 1fc380ea9e7cd..6f83028dd9e6a 100644 --- a/src/Symfony/Component/Validator/Constraints/UrlValidator.php +++ b/src/Symfony/Component/Validator/Constraints/UrlValidator.php @@ -42,6 +42,10 @@ class UrlValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof Url) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Url'); + } + if (null === $value || '' === $value) { return; } 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