This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Validator/ConstraintValidator.php

120 lines
3.0 KiB
PHP
Raw Normal View History

<?php
2010-10-02 11:42:31 +01:00
/*
* This file is part of the Symfony package.
2010-10-02 11:42:31 +01:00
*
* (c) Fabien Potencier <fabien@symfony.com>
2010-10-02 11:42:31 +01:00
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
2010-10-02 11:42:31 +01:00
*/
namespace Symfony\Component\Validator;
use Symfony\Component\Validator\Exception\ValidatorException;
/**
* Base class for constraint validators
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
2011-07-20 09:37:57 +01:00
* @api
*/
abstract class ConstraintValidator implements ConstraintValidatorInterface
{
2011-05-17 22:04:13 +01:00
/**
* @var ExecutionContextInterface
2011-05-17 22:04:13 +01:00
*/
protected $context;
2011-05-17 22:04:13 +01:00
/**
* @var string
*
* @deprecated
2011-05-17 22:04:13 +01:00
*/
private $messageTemplate;
2011-05-17 22:04:13 +01:00
/**
* @var array
*
* @deprecated
2011-05-17 22:04:13 +01:00
*/
private $messageParameters;
/**
* {@inheritDoc}
*/
public function initialize(ExecutionContextInterface $context)
{
$this->context = $context;
$this->messageTemplate = '';
$this->messageParameters = array();
}
/**
* {@inheritDoc}
2011-07-20 09:37:57 +01:00
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3.
*/
public function getMessageTemplate()
{
trigger_error('getMessageTemplate() is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
return $this->messageTemplate;
}
/**
* {@inheritDoc}
2011-07-20 09:37:57 +01:00
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3.
*/
public function getMessageParameters()
{
trigger_error('getMessageParameters() is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
return $this->messageParameters;
}
2011-07-20 09:37:57 +01:00
/**
* Wrapper for $this->context->addViolation()
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3.
2011-07-20 09:37:57 +01:00
*/
protected function setMessage($template, array $parameters = array())
{
trigger_error('setMessage() is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
$this->messageTemplate = $template;
$this->messageParameters = $parameters;
if (!$this->context instanceof ExecutionContext) {
throw new ValidatorException('ConstraintValidator::initialize() must be called before setting violation messages');
}
$this->context->addViolation($template, $parameters);
}
/**
* Stub implementation delegating to the deprecated isValid method.
*
* This stub exists for BC and will be dropped in Symfony 2.3.
*
* @see ConstraintValidatorInterface::validate
*/
public function validate($value, Constraint $constraint)
{
trigger_error('isValid() is deprecated since version 2.1 and will be removed in 2.3. Implement validate() instead.', E_USER_DEPRECATED);
return $this->isValid($value, $constraint);
}
/**
* BC variant of validate.
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3.
*/
protected function isValid($value, Constraint $constraint)
{
}
2011-06-08 11:16:48 +01:00
}