From c6d39ed61f1951a3bb3ca083331a61df6ae9281d Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Tue, 1 Mar 2011 23:35:57 +0100 Subject: [PATCH 1/2] [Validator] Date: check if the value is a DateTime instance --- src/Symfony/Component/Validator/Constraints/DateValidator.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Symfony/Component/Validator/Constraints/DateValidator.php b/src/Symfony/Component/Validator/Constraints/DateValidator.php index da437dbfdfb62..43a4422e321c6 100644 --- a/src/Symfony/Component/Validator/Constraints/DateValidator.php +++ b/src/Symfony/Component/Validator/Constraints/DateValidator.php @@ -25,6 +25,10 @@ public function isValid($value, Constraint $constraint) return true; } + if ($value instanceof \DateTime) { + return true; + } + if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString()'))) { throw new UnexpectedTypeException($value, 'string'); } From 886149fa0028189b0ac09c401dc6ff0ac054ecb3 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Tue, 1 Mar 2011 23:37:10 +0100 Subject: [PATCH 2/2] [Validator] Refactoring DateTimeValidator and DateValidator --- .../Constraints/DateTimeValidator.php | 31 +------------------ .../Validator/Constraints/DateValidator.php | 2 +- 2 files changed, 2 insertions(+), 31 deletions(-) diff --git a/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php b/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php index 8d86d40215aec..5959040ecb3c8 100644 --- a/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php @@ -11,36 +11,7 @@ namespace Symfony\Component\Validator\Constraints; -use Symfony\Component\Validator\Constraint; -use Symfony\Component\Validator\ConstraintValidator; -use Symfony\Component\Validator\Exception\UnexpectedTypeException; - -class DateTimeValidator extends ConstraintValidator +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])$/'; - - public function isValid($value, Constraint $constraint) - { - if (null === $value || '' === $value) { - return true; - } - - if ($value instanceof \DateTime) { - return true; - } - - if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString()'))) { - throw new UnexpectedTypeException($value, 'string'); - } - - $value = (string) $value; - - if (!preg_match(self::PATTERN, $value, $matches)) { - $this->setMessage($constraint->message, array('{{ value }}' => $value)); - - return false; - } - - return checkdate($matches[2], $matches[3], $matches[1]); - } } \ No newline at end of file diff --git a/src/Symfony/Component/Validator/Constraints/DateValidator.php b/src/Symfony/Component/Validator/Constraints/DateValidator.php index 43a4422e321c6..42518bb94b16c 100644 --- a/src/Symfony/Component/Validator/Constraints/DateValidator.php +++ b/src/Symfony/Component/Validator/Constraints/DateValidator.php @@ -35,7 +35,7 @@ public function isValid($value, Constraint $constraint) $value = (string) $value; - if (!preg_match(self::PATTERN, $value, $matches)) { + if (!preg_match(static::PATTERN, $value, $matches)) { $this->setMessage($constraint->message, array('{{ value }}' => $value)); return false; 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