df3d543349
* 2.4: made types consistent with those defined in Hack made {@inheritdoc} annotations consistent across the board made {@inheritdoc} annotations consistent across the board fixed types in phpdocs [Debug] Fixed ClassNotFoundFatalErrorHandler on windows. made phpdoc types consistent with those defined in Hack Add support Thai translations [Validator] Add missing czech translations made types consistent with those defined in Hack removed extra/unsupported arguments [HttpKernel] fixed an error message [TwigBundle] removed undefined argument [Translation] Make IcuDatFileLoader/IcuResFileLoader::load invalid resource compatible with HHVM. Conflicts: src/Symfony/Component/Console/Helper/TableHelper.php src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php src/Symfony/Component/Form/FormError.php src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php src/Symfony/Component/Process/ProcessPipes.php src/Symfony/Component/PropertyAccess/PropertyAccessor.php src/Symfony/Component/Security/Acl/Dbal/MutableAclProvider.php src/Symfony/Component/Security/Http/RememberMe/TokenBasedRememberMeServices.php src/Symfony/Component/Translation/Dumper/FileDumper.php src/Symfony/Component/Validator/ConstraintViolation.php src/Symfony/Component/Validator/Constraints/EmailValidator.php src/Symfony/Component/Validator/ExecutionContextInterface.php src/Symfony/Component/Validator/Mapping/BlackholeMetadataFactory.php
51 lines
1.3 KiB
PHP
51 lines
1.3 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Symfony package.
|
|
*
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Symfony\Component\Validator\Constraints;
|
|
|
|
use Symfony\Component\Validator\Constraint;
|
|
use Symfony\Component\Validator\ConstraintValidator;
|
|
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
|
|
|
/**
|
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
|
*
|
|
* @api
|
|
*/
|
|
class TimeValidator extends ConstraintValidator
|
|
{
|
|
const PATTERN = '/^(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 Time) {
|
|
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Time');
|
|
}
|
|
|
|
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)) {
|
|
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
|
|
}
|
|
}
|
|
}
|