[Validator] Trigger errors for deprecations

This commit is contained in:
Colin Frei 2012-12-06 21:23:28 +01:00
parent 1f9eb7f292
commit 3241157114
16 changed files with 108 additions and 1 deletions

View File

@ -58,6 +58,8 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface
*/
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;
}
@ -68,6 +70,8 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface
*/
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;
}
@ -78,6 +82,8 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface
*/
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;
@ -107,5 +113,6 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface
*/
protected function isValid($value, Constraint $constraint)
{
trigger_error('isValid() is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
}
}

View File

@ -26,6 +26,13 @@ class Max extends Constraint
public $invalidMessage = 'This value should be a valid number.';
public $limit;
public function __construct($options = null)
{
trigger_error('Max is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
parent::__construct($options);
}
/**
* {@inheritDoc}
*/

View File

@ -26,6 +26,13 @@ class MaxLength extends Constraint
public $limit;
public $charset = 'UTF-8';
public function __construct($options = null)
{
trigger_error('MaxLength is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
parent::__construct($options);
}
/**
* {@inheritDoc}
*/

View File

@ -24,6 +24,11 @@ use Symfony\Component\Validator\Exception\UnexpectedTypeException;
*/
class MaxLengthValidator extends ConstraintValidator
{
public function __construct($options = null)
{
trigger_error('MaxLengthValidator is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
}
/**
* {@inheritDoc}
*/

View File

@ -23,6 +23,11 @@ use Symfony\Component\Validator\ConstraintValidator;
*/
class MaxValidator extends ConstraintValidator
{
public function __construct($options = null)
{
trigger_error('MaxValidator is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
}
/**
* {@inheritDoc}
*/

View File

@ -26,6 +26,13 @@ class Min extends Constraint
public $invalidMessage = 'This value should be a valid number.';
public $limit;
public function __construct($options = null)
{
trigger_error('Min is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
parent::__construct($options);
}
/**
* {@inheritDoc}
*/

View File

@ -26,6 +26,13 @@ class MinLength extends Constraint
public $limit;
public $charset = 'UTF-8';
public function __construct($options = null)
{
trigger_error('MinLength is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
parent::__construct($options);
}
/**
* {@inheritDoc}
*/

View File

@ -24,6 +24,11 @@ use Symfony\Component\Validator\Exception\UnexpectedTypeException;
*/
class MinLengthValidator extends ConstraintValidator
{
public function __construct($options = null)
{
trigger_error('MinLengthValidator is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
}
/**
* {@inheritDoc}
*/

View File

@ -23,6 +23,11 @@ use Symfony\Component\Validator\ConstraintValidator;
*/
class MinValidator extends ConstraintValidator
{
public function __construct($options = null)
{
trigger_error('MinValidator is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
}
/**
* Checks if the passed value is valid.
*

View File

@ -100,6 +100,8 @@ class ExecutionContext implements ExecutionContextInterface
*/
public function addViolationAtPath($propertyPath, $message, array $params = array(), $invalidValue = null, $pluralization = null, $code = null)
{
trigger_error('addViolationAtPath() is deprecated since version 2.2 and will be removed in 2.3.', E_USER_DEPRECATED);
$this->globalContext->getViolations()->add(new ConstraintViolation(
$message,
$params,
@ -124,10 +126,12 @@ class ExecutionContext implements ExecutionContextInterface
* @param integer|null $code The violation code.
*
* @deprecated Deprecated since version 2.2, to be removed in 2.3. Use the
* method {@link atViolationAt} instead.
* method {@link addViolationAt} instead.
*/
public function addViolationAtSubPath($subPath, $message, array $params = array(), $invalidValue = null, $pluralization = null, $code = null)
{
trigger_error('addViolationAtSubPath() is deprecated since version 2.2 and will be removed in 2.3. Use addViolationAt() instead.', E_USER_DEPRECATED);
if (func_num_args() >= 4) {
$this->addViolationAt($subPath, $message, $params, $invalidValue, $pluralization, $code);
} else {
@ -288,6 +292,8 @@ class ExecutionContext implements ExecutionContextInterface
*/
public function getCurrentClass()
{
trigger_error('getCurrentClass() is deprecated since version 2.2 and will be removed in 2.3. Use getClassName() instead', E_USER_DEPRECATED);
return $this->getClassName();
}
@ -304,6 +310,8 @@ class ExecutionContext implements ExecutionContextInterface
*/
public function getCurrentProperty()
{
trigger_error('getCurrentProperty() is deprecated since version 2.2 and will be removed in 2.3. Use getClassName() instead', E_USER_DEPRECATED);
return $this->getPropertyName();
}
@ -319,6 +327,8 @@ class ExecutionContext implements ExecutionContextInterface
*/
public function getCurrentValue()
{
trigger_error('getCurrentValue() is deprecated since version 2.2 and will be removed in 2.3. Use getValue() instead', E_USER_DEPRECATED);
return $this->value;
}
@ -332,6 +342,8 @@ class ExecutionContext implements ExecutionContextInterface
*/
public function getGraphWalker()
{
trigger_error('getGraphWalker() is deprecated since version 2.2 and will be removed in 2.3. Use validate() and validateValue() instead', E_USER_DEPRECATED);
return $this->globalContext->getVisitor()->getGraphWalker();
}

View File

@ -55,6 +55,8 @@ class GraphWalker
*/
public function __construct(ValidationVisitor $visitor, MetadataFactoryInterface $metadataFactory, array &$validatedObjects = array())
{
trigger_error('GraphWalker is deprecated since version 2.2 and will be removed in 2.3. This class has been replaced by ValidationVisitorInterface and MetadataInterface.', E_USER_DEPRECATED);
$this->visitor = $visitor;
$this->metadataFactory = $metadataFactory;
$this->validatedObjects = &$validatedObjects;
@ -67,6 +69,8 @@ class GraphWalker
*/
public function getViolations()
{
trigger_error('getViolations() is deprecated since version 2.2 and will be removed in 2.3.', E_USER_DEPRECATED);
return $this->visitor->getViolations();
}
@ -83,6 +87,8 @@ class GraphWalker
*/
public function walkObject(ClassMetadata $metadata, $object, $group, $propertyPath)
{
trigger_error('walkObject() is deprecated since version 2.2 and will be removed in 2.3.', E_USER_DEPRECATED);
$hash = spl_object_hash($object);
// Exit, if the object is already validated for the current group
@ -118,6 +124,8 @@ class GraphWalker
*/
public function walkProperty(ClassMetadata $metadata, $property, $object, $group, $propertyPath, $propagatedGroup = null)
{
trigger_error('walkProperty() is deprecated since version 2.2 and will be removed in 2.3.', E_USER_DEPRECATED);
if (!is_object($object)) {
throw new UnexpectedTypeException($object, 'object');
}
@ -140,6 +148,8 @@ class GraphWalker
*/
public function walkPropertyValue(ClassMetadata $metadata, $property, $value, $group, $propertyPath)
{
trigger_error('walkPropertyValue() is deprecated since version 2.2 and will be removed in 2.3.', E_USER_DEPRECATED);
foreach ($metadata->getMemberMetadatas($property) as $member) {
$member->accept($this->visitor, $value, $group, $propertyPath);
}
@ -163,6 +173,8 @@ class GraphWalker
*/
public function walkReference($value, $group, $propertyPath, $traverse, $deep = false)
{
trigger_error('walkReference() is deprecated since version 2.2 and will be removed in 2.3.', E_USER_DEPRECATED);
$this->visitor->validate($value, $group, $propertyPath, $traverse, $deep);
}
@ -180,6 +192,8 @@ class GraphWalker
*/
public function walkConstraint(Constraint $constraint, $value, $group, $propertyPath, $currentClass = null, $currentProperty = null)
{
trigger_error('walkConstraint() is deprecated since version 2.2 and will be removed in 2.3.', E_USER_DEPRECATED);
$metadata = null;
// BC code to make getCurrentClass() and getCurrentProperty() work when

View File

@ -118,6 +118,8 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface, MetadataFac
*/
public function getClassMetadata($class)
{
trigger_error('getClassMetadata() is deprecated since version 2.2 and will be removed in 2.3. Use getMetadataFor() instead.', E_USER_DEPRECATED);
return $this->getMetadataFor($class);
}
}

View File

@ -194,6 +194,8 @@ abstract class MemberMetadata extends ElementMetadata implements PropertyMetadat
*/
public function getValue($object)
{
trigger_error('getValue() is deprecated since version 2.2 and will be removed in 2.3. Use getPropertyValue() instead.', E_USER_DEPRECATED);
return $this->getPropertyValue($object);
}

View File

@ -155,6 +155,8 @@ class ValidationVisitor implements ValidationVisitorInterface, GlobalExecutionCo
*/
public function getGraphWalker()
{
trigger_error('getGraphWalker() is deprecated since version 2.2 and will be removed in 2.3.', E_USER_DEPRECATED);
if (null === $this->graphWalker) {
$this->graphWalker = new GraphWalker($this, $this->metadataFactory, $this->validatedObjects);
}

View File

@ -49,6 +49,8 @@ class ValidatorContext implements ValidatorContextInterface
*/
public function setClassMetadataFactory(ClassMetadataFactoryInterface $classMetadataFactory)
{
trigger_error('setClassMetadataFactory() is deprecated since version 2.1 and will be removed in 2.3. Use Validation::createValidatorBuilder() instead.', E_USER_DEPRECATED);
if ($classMetadataFactory instanceof MetadataFactoryInterface) {
$this->metadataFactory = $classMetadataFactory;
} else {
@ -68,6 +70,8 @@ class ValidatorContext implements ValidatorContextInterface
*/
public function setConstraintValidatorFactory(ConstraintValidatorFactoryInterface $constraintValidatorFactory)
{
trigger_error('setConstraintValidatorFactory() is deprecated since version 2.1 and will be removed in 2.3. Use Validation::createValidatorBuilder() instead.', E_USER_DEPRECATED);
$this->constraintValidatorFactory = $constraintValidatorFactory;
return $this;
@ -81,6 +85,8 @@ class ValidatorContext implements ValidatorContextInterface
*/
public function getValidator()
{
trigger_error('getValidator() is deprecated since version 2.1 and will be removed in 2.3. Use Validation::createValidator() instead.', E_USER_DEPRECATED);
return new Validator(
$this->metadataFactory,
$this->constraintValidatorFactory
@ -96,6 +102,8 @@ class ValidatorContext implements ValidatorContextInterface
*/
public function getClassMetadataFactory()
{
trigger_error('getClassMetadataFactory() is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
return $this->classMetadataFactory;
}
@ -108,6 +116,8 @@ class ValidatorContext implements ValidatorContextInterface
*/
public function getConstraintValidatorFactory()
{
trigger_error('getConstraintValidatorFactory() is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
return $this->constraintValidatorFactory;
}
}

View File

@ -109,6 +109,8 @@ class ValidatorFactory implements ValidatorContextInterface
*/
public static function buildDefault(array $mappingFiles = array(), $annotations = false, $staticMethod = null)
{
trigger_error('buildDefault() is deprecated since version 2.1 and will be removed in 2.3. Use Validation::createValidatorBuilder() instead.', E_USER_DEPRECATED);
$xmlMappingFiles = array();
$yamlMappingFiles = array();
$loaders = array();
@ -170,6 +172,8 @@ class ValidatorFactory implements ValidatorContextInterface
*/
public function __construct(ValidatorContextInterface $defaultContext = null)
{
trigger_error('ValidatorFactory is deprecated since version 2.1 and will be removed in 2.3. Use Validation::createValidatorBuilder() instead.', E_USER_DEPRECATED);
$this->defaultContext = null === $defaultContext ? new ValidatorContext() : $defaultContext;
}
@ -186,6 +190,8 @@ class ValidatorFactory implements ValidatorContextInterface
*/
public function setClassMetadataFactory(ClassMetadataFactoryInterface $metadataFactory)
{
trigger_error('setClassMetadataFactory() is deprecated since version 2.1 and will be removed in 2.3. Use Validation::createValidatorBuilder() instead.', E_USER_DEPRECATED);
$context = clone $this->defaultContext;
return $context->setClassMetadataFactory($metadataFactory);
@ -204,6 +210,8 @@ class ValidatorFactory implements ValidatorContextInterface
*/
public function setConstraintValidatorFactory(ConstraintValidatorFactoryInterface $validatorFactory)
{
trigger_error('setConstraintValidatorFactory() is deprecated since version 2.1 and will be removed in 2.3. Use Validation::createValidatorBuilder() instead.', E_USER_DEPRECATED);
$context = clone $this->defaultContext;
return $context->setConstraintValidatorFactory($validatorFactory);
@ -219,6 +227,8 @@ class ValidatorFactory implements ValidatorContextInterface
*/
public function getValidator()
{
trigger_error('getValidator() is deprecated since version 2.1 and will be removed in 2.3. Use Validation::createValidator() instead.', E_USER_DEPRECATED);
return $this->defaultContext->getValidator();
}
}