Skip to content

Commit

Permalink
[Validator] adds more deprecation notices.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Hamon committed Jan 5, 2015
1 parent a7f841e commit cd9617a
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 46 deletions.
4 changes: 2 additions & 2 deletions src/Symfony/Component/Validator/ConstraintValidator.php
Expand Up @@ -61,7 +61,7 @@ public function initialize(ExecutionContextInterface $context)
*
* @return ConstraintViolationBuilderInterface The violation builder
*
* @deprecated This method will be removed in Symfony 3.0.
* @deprecated since version 2.5, to be removed in 3.0.
*/
protected function buildViolation($message, array $parameters = array())
{
Expand All @@ -84,7 +84,7 @@ protected function buildViolation($message, array $parameters = array())
*
* @return ConstraintViolationBuilderInterface The violation builder
*
* @deprecated This method will be removed in Symfony 3.0.
* @deprecated since version 2.5, to be removed in 3.0.
*/
protected function buildViolationInContext(ExecutionContextInterface $context, $message, array $parameters = array())
{
Expand Down
30 changes: 18 additions & 12 deletions src/Symfony/Component/Validator/Constraints/GroupSequence.php
Expand Up @@ -97,12 +97,13 @@ public function __construct(array $groups)
/**
* Returns an iterator for this group.
*
* Implemented for backwards compatibility with Symfony < 2.5.
*
* @return \Traversable The iterator
*
* @see \IteratorAggregate::getIterator()
*
* @deprecated Implemented for backwards compatibility with Symfony < 2.5.
* To be removed in Symfony 3.0.
* @deprecated since version 2.5, to be removed in Symfony 3.0.
*/
public function getIterator()
{
Expand All @@ -114,12 +115,13 @@ public function getIterator()
/**
* Returns whether the given offset exists in the sequence.
*
* Implemented for backwards compatibility with Symfony < 2.5.
*
* @param int $offset The offset
*
* @return bool Whether the offset exists
*
* @deprecated Implemented for backwards compatibility with Symfony < 2.5.
* To be removed in Symfony 3.0.
* @deprecated since version 2.5, to be removed in Symfony 3.0.
*/
public function offsetExists($offset)
{
Expand All @@ -131,14 +133,15 @@ public function offsetExists($offset)
/**
* Returns the group at the given offset.
*
* Implemented for backwards compatibility with Symfony < 2.5.
*
* @param int $offset The offset
*
* @return string The group a the given offset
*
* @throws OutOfBoundsException If the object does not exist
*
* @deprecated Implemented for backwards compatibility with Symfony < 2.5.
* To be removed in Symfony 3.0.
* @deprecated since version 2.5, to be removed in Symfony 3.0.
*/
public function offsetGet($offset)
{
Expand All @@ -157,11 +160,12 @@ public function offsetGet($offset)
/**
* Sets the group at the given offset.
*
* Implemented for backwards compatibility with Symfony < 2.5.
*
* @param int $offset The offset
* @param string $value The group name
*
* @deprecated Implemented for backwards compatibility with Symfony < 2.5.
* To be removed in Symfony 3.0.
* @deprecated since version 2.5, to be removed in Symfony 3.0.
*/
public function offsetSet($offset, $value)
{
Expand All @@ -179,10 +183,11 @@ public function offsetSet($offset, $value)
/**
* Removes the group at the given offset.
*
* Implemented for backwards compatibility with Symfony < 2.5.
*
* @param int $offset The offset
*
* @deprecated Implemented for backwards compatibility with Symfony < 2.5.
* To be removed in Symfony 3.0.
* @deprecated since version 2.5, to be removed in Symfony 3.0.
*/
public function offsetUnset($offset)
{
Expand All @@ -194,10 +199,11 @@ public function offsetUnset($offset)
/**
* Returns the number of groups in the sequence.
*
* Implemented for backwards compatibility with Symfony < 2.5.
*
* @return int The number of groups
*
* @deprecated Implemented for backwards compatibility with Symfony < 2.5.
* To be removed in Symfony 3.0.
* @deprecated since version 2.5, to be removed in Symfony 3.0.
*/
public function count()
{
Expand Down
20 changes: 16 additions & 4 deletions src/Symfony/Component/Validator/Context/ExecutionContext.php
Expand Up @@ -187,8 +187,10 @@ public function addViolation($message, array $parameters = array(), $invalidValu
// API, as they are not present in the new interface anymore.
// You should use buildViolation() instead.
if (func_num_args() > 2) {
trigger_error('The parameters $invalidValue, $plural and $code in method '.__METHOD__.' are deprecated since version 2.5 and will be removed in 3.0. Use the '.__CLASS__.'::buildViolation method instead.', E_USER_DEPRECATED);

throw new BadMethodCallException(
'The parameters $invalidValue, $pluralization and $code are '.
'The parameters $invalidValue, $plural and $code are '.
'not supported anymore as of Symfony 2.5. Please use '.
'buildViolation() instead or enable the legacy mode.'
);
Expand Down Expand Up @@ -286,7 +288,13 @@ public function getGroup()
*/
public function getClassName()
{
return $this->metadata instanceof ClassBasedInterface ? $this->metadata->getClassName() : null;
if ($this->metadata instanceof ClassBasedInterface) {
trigger_error('The Symfony\Component\Validator\ClassBasedInterface interface is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);

return $this->metadata->getClassName();
}

return null;
}

/**
Expand All @@ -310,6 +318,8 @@ public function getPropertyPath($subPath = '')
*/
public function addViolationAt($subPath, $message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null)
{
trigger_error('The '.__METHOD__.' is deprecated since version 2.5 and will be removed in 3.0. Use the '.__CLASS__.'::buildViolation method instead.', E_USER_DEPRECATED);

throw new BadMethodCallException(
'addViolationAt() is not supported anymore as of Symfony 2.5. '.
'Please use buildViolation() instead or enable the legacy mode.'
Expand All @@ -321,7 +331,7 @@ public function addViolationAt($subPath, $message, array $parameters = array(),
*/
public function validate($value, $subPath = '', $groups = null, $traverse = false, $deep = false)
{
trigger_error('ExecutionContext::validate() is deprecated since version 2.5 and will be removed in 3.0. Use ExecutionContext::getValidator() together with inContext() instead.', E_USER_DEPRECATED);
trigger_error('The '.__METHOD__.' is deprecated since version 2.5 and will be removed in 3.0. Use the '.__CLASS__.'::getValidator method together with Symfony\Component\Validator\Validator\ValidatorInterface::inContext method instead.', E_USER_DEPRECATED);

throw new BadMethodCallException(
'validate() is not supported anymore as of Symfony 2.5. '.
Expand All @@ -334,7 +344,7 @@ public function validate($value, $subPath = '', $groups = null, $traverse = fals
*/
public function validateValue($value, $constraints, $subPath = '', $groups = null)
{
trigger_error('ExecutionContext::validateValue() is deprecated since version 2.5 and will be removed in 3.0. Use ExecutionContext::getValidator() together with inContext() instead.', E_USER_DEPRECATED);
trigger_error('The '.__METHOD__.' is deprecated since version 2.5 and will be removed in 3.0. Use the '.__CLASS__.'::getValidator method together with Symfony\Component\Validator\Validator\ValidatorInterface::inContext method instead.', E_USER_DEPRECATED);

throw new BadMethodCallException(
'validateValue() is not supported anymore as of Symfony 2.5. '.
Expand All @@ -347,6 +357,8 @@ public function validateValue($value, $constraints, $subPath = '', $groups = nul
*/
public function getMetadataFactory()
{
trigger_error('The '.__METHOD__.' is deprecated since version 2.5 and will be removed in 3.0. Use the '.__CLASS__.'::getValidator method together with Symfony\Component\Validator\Validator\ValidatorInterface::getMetadataFor or Symfony\Component\Validator\Validator\ValidatorInterface::hasMetadataFor method instead.', E_USER_DEPRECATED);

throw new BadMethodCallException(
'getMetadataFactory() is not supported anymore as of Symfony 2.5. '.
'Please use getValidator() in combination with getMetadataFor() '.
Expand Down
15 changes: 11 additions & 4 deletions src/Symfony/Component/Validator/Context/LegacyExecutionContext.php
Expand Up @@ -11,8 +11,6 @@

namespace Symfony\Component\Validator\Context;

trigger_error('The '.__NAMESPACE__.'\LegacyExecutionContext class is deprecated since version 2.5 and will be removed in 3.0. Use the new Symfony\Component\Validator\Context\ExecutionContext class instead.', E_USER_DEPRECATED);

use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Validator\Constraints\Valid;
use Symfony\Component\Validator\MetadataFactoryInterface;
Expand All @@ -24,8 +22,7 @@
* @since 2.5
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated Implemented for backward compatibility with Symfony < 2.5.
* To be removed in Symfony 3.0.
* @deprecated since version 2.5, to be removed in 3.0.
*/
class LegacyExecutionContext extends ExecutionContext
{
Expand All @@ -44,6 +41,8 @@ class LegacyExecutionContext extends ExecutionContext
*/
public function __construct(ValidatorInterface $validator, $root, MetadataFactoryInterface $metadataFactory, TranslatorInterface $translator, $translationDomain = null)
{
trigger_error('The '.__CLASS__.' class is deprecated since version 2.5 and will be removed in 3.0. Use the new Symfony\Component\Validator\Context\ExecutionContext class instead.', E_USER_DEPRECATED);

parent::__construct(
$validator,
$root,
Expand All @@ -60,6 +59,8 @@ public function __construct(ValidatorInterface $validator, $root, MetadataFactor
public function addViolation($message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null)
{
if (func_num_args() > 2) {
trigger_error('The parameters $invalidValue, $plural and $code in method '.__METHOD__.' are deprecated since version 2.5 and will be removed in 3.0. Use the '.__CLASS__.'::buildViolation method instead.', E_USER_DEPRECATED);

$this
->buildViolation($message, $parameters)
->setInvalidValue($invalidValue)
Expand All @@ -79,6 +80,8 @@ public function addViolation($message, array $parameters = array(), $invalidValu
*/
public function addViolationAt($subPath, $message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null)
{
trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0. Use the '.__CLASS__.'::buildViolation method instead.', E_USER_DEPRECATED);

if (func_num_args() > 2) {
$this
->buildViolation($message, $parameters)
Expand Down Expand Up @@ -140,6 +143,8 @@ public function validate($value, $subPath = '', $groups = null, $traverse = fals
*/
public function validateValue($value, $constraints, $subPath = '', $groups = null)
{
trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0. Use the '.__CLASS__.'::validate method instead.', E_USER_DEPRECATED);

return $this
->getValidator()
->inContext($this)
Expand All @@ -153,6 +158,8 @@ public function validateValue($value, $constraints, $subPath = '', $groups = nul
*/
public function getMetadataFactory()
{
trigger_error('The '.__METHOD__.' is deprecated since version 2.5 and will be removed in 3.0. Use the new Symfony\Component\Validator\Context\ExecutionContext::getValidator method in combination with Symfony\Component\Validator\Validator\ValidatorInterface::getMetadataFor or Symfony\Component\Validator\Validator\ValidatorInterface::hasMetadataFor method instead.', E_USER_DEPRECATED);

return $this->metadataFactory;
}
}
Expand Up @@ -11,18 +11,21 @@

namespace Symfony\Component\Validator\Context;

trigger_error('The '.__NAMESPACE__.'\LegacyExecutionContextFactory is deprecated since version 2.5 and will be removed in 3.0.');

use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Validator\MetadataFactoryInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;

/**
* Creates new {@link LegacyExecutionContext} instances.
*
* Implemented for backward compatibility with Symfony < 2.5.
*
* @since 2.5
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated Implemented for backward compatibility with Symfony < 2.5.
* To be removed in Symfony 3.0.
* @deprecated since version 2.5, to be removed in 3.0.
*/
class LegacyExecutionContextFactory implements ExecutionContextFactoryInterface
{
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Validator/ExecutionContextInterface.php
Expand Up @@ -99,9 +99,9 @@ interface ExecutionContextInterface
*
* @api
*
* @deprecated The parameters $invalidValue, $pluralization and $code are
* deprecated since version 2.5 and will be removed in
* Symfony 3.0.
* @deprecated since version 2.5.
* The parameters $invalidValue, $plural and $code will be removed
* in 3.0.
*/
public function addViolation($message, array $params = array(), $invalidValue = null, $plural = null, $code = null);

Expand Down
@@ -0,0 +1,27 @@
<?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\Mapping\Deprecated;

trigger_error('Constants STOP_RECURSION in class Symfony\Component\Validator\Mapping\TraversalStrategy is deprecated since version 2.3 and will be removed in 3.0.', E_USER_DEPRECATED);

/**
* @deprecated since version 2.7, to be removed in 3.0.
* @internal
*/
final class TraversalStrategy
{
const STOP_RECURSION = 8;

private function __construct()
{
}
}
5 changes: 3 additions & 2 deletions src/Symfony/Component/Validator/Mapping/GenericMetadata.php
Expand Up @@ -231,10 +231,11 @@ public function getTraversalStrategy()
*
* Should not be used.
*
* Implemented for backward compatibility with Symfony < 2.5.
*
* @throws BadMethodCallException
*
* @deprecated Implemented for backward compatibility with Symfony < 2.5.
* Will be removed in Symfony 3.0.
* @deprecated since version 2.5, to be removed in 3.0.
*/
public function accept(ValidationVisitorInterface $visitor, $value, $group, $propertyPath)
{
Expand Down
9 changes: 6 additions & 3 deletions src/Symfony/Component/Validator/Mapping/TraversalStrategy.php
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Component\Validator\Mapping;

use Symfony\Component\Validator\Mapping\Deprecated\TraversalStrategy as Deprecated;

/**
* Specifies whether and how a traversable object should be traversed.
*
Expand Down Expand Up @@ -51,10 +53,11 @@ class TraversalStrategy
* Specifies that nested instances of {@link \Traversable} should never be
* iterated. Can be combined with {@link IMPLICIT} or {@link TRAVERSE}.
*
* @deprecated This constant was added for backward compatibility only.
* It will be removed in Symfony 3.0.
* This constant was added for backward compatibility only.
*
* @deprecated since version 2.5, to be removed in 3.0.
*/
const STOP_RECURSION = 8;
const STOP_RECURSION = Deprecated::STOP_RECURSION;

/**
* Not instantiable.
Expand Down
2 changes: 0 additions & 2 deletions src/Symfony/Component/Validator/ValidationVisitor.php
Expand Up @@ -81,8 +81,6 @@ class ValidationVisitor implements ValidationVisitorInterface, GlobalExecutionCo
*/
public function __construct($root, MetadataFactoryInterface $metadataFactory, ConstraintValidatorFactoryInterface $validatorFactory, TranslatorInterface $translator, $translationDomain = null, array $objectInitializers = array())
{
trigger_error('Symfony\Component\Validator\ValidationVisitor was deprecated in version 2.5 and will be removed in version 3.0.', E_USER_DEPRECATED);

foreach ($objectInitializers as $initializer) {
if (!$initializer instanceof ObjectInitializerInterface) {
throw new UnexpectedTypeException($initializer, 'Symfony\Component\Validator\ObjectInitializerInterface');
Expand Down
Expand Up @@ -64,8 +64,6 @@ interface ValidationVisitorInterface
*
* @throws Exception\NoSuchMetadataException If no metadata can be found for
* the given value.
*
* @deprecated since version 2.5, to be removed in 3.0.
*/
public function validate($value, $group, $propertyPath, $traverse = false, $deep = false);

Expand All @@ -79,8 +77,6 @@ public function validate($value, $group, $propertyPath, $traverse = false, $deep
* @param mixed $value The value to validate.
* @param string $group The validation group to validate.
* @param string $propertyPath The current property path in the validation graph.
*
* @deprecated since version 2.5, to be removed in 3.0.
*/
public function visit(MetadataInterface $metadata, $value, $group, $propertyPath);
}

0 comments on commit cd9617a

Please sign in to comment.