diff --git a/src/Symfony/Component/Form/Extension/Validator/EventListener/ValidationListener.php b/src/Symfony/Component/Form/Extension/Validator/EventListener/ValidationListener.php index 4bebce09cd574..0aae4bb8536b7 100644 --- a/src/Symfony/Component/Form/Extension/Validator/EventListener/ValidationListener.php +++ b/src/Symfony/Component/Form/Extension/Validator/EventListener/ValidationListener.php @@ -14,7 +14,6 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Form\Extension\Validator\ViolationMapper\ViolationMapperInterface; use Symfony\Component\Validator\Validator\ValidatorInterface; -use Symfony\Component\Validator\ValidatorInterface as LegacyValidatorInterface; use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\Extension\Validator\Constraints\Form; @@ -37,15 +36,11 @@ public static function getSubscribedEvents() } /** - * @param ValidatorInterface|LegacyValidatorInterface $validator - * @param ViolationMapperInterface $violationMapper + * @param ValidatorInterface $validator + * @param ViolationMapperInterface $violationMapper */ - public function __construct($validator, ViolationMapperInterface $violationMapper) + public function __construct(ValidatorInterface $validator, ViolationMapperInterface $violationMapper) { - if (!$validator instanceof ValidatorInterface && !$validator instanceof LegacyValidatorInterface) { - throw new \InvalidArgumentException('Validator must be instance of Symfony\Component\Validator\Validator\ValidatorInterface or Symfony\Component\Validator\ValidatorInterface'); - } - $this->validator = $validator; $this->violationMapper = $violationMapper; } diff --git a/src/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php b/src/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php index 066a3d9eec3f7..bd6483c5595d7 100644 --- a/src/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php +++ b/src/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php @@ -15,7 +15,6 @@ use Symfony\Component\Form\Extension\Validator\ViolationMapper\ViolationMapper; use Symfony\Component\Form\Extension\Validator\EventListener\ValidationListener; use Symfony\Component\Validator\Validator\ValidatorInterface; -use Symfony\Component\Validator\ValidatorInterface as LegacyValidatorInterface; use Symfony\Component\OptionsResolver\Options; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -35,14 +34,10 @@ class FormTypeValidatorExtension extends BaseValidatorExtension private $violationMapper; /** - * @param ValidatorInterface|LegacyValidatorInterface $validator + * @param ValidatorInterface $validator */ - public function __construct($validator) + public function __construct(ValidatorInterface $validator) { - if (!$validator instanceof ValidatorInterface && !$validator instanceof LegacyValidatorInterface) { - throw new \InvalidArgumentException('Validator must be instance of Symfony\Component\Validator\Validator\ValidatorInterface or Symfony\Component\Validator\ValidatorInterface'); - } - $this->validator = $validator; $this->violationMapper = new ViolationMapper(); } diff --git a/src/Symfony/Component/Form/Extension/Validator/ValidatorExtension.php b/src/Symfony/Component/Form/Extension/Validator/ValidatorExtension.php index e7ed95c459d03..3fe14187bda02 100644 --- a/src/Symfony/Component/Form/Extension/Validator/ValidatorExtension.php +++ b/src/Symfony/Component/Form/Extension/Validator/ValidatorExtension.php @@ -17,7 +17,6 @@ use Symfony\Component\Validator\Constraints\Valid; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Validator\ValidatorInterface; -use Symfony\Component\Validator\ValidatorInterface as LegacyValidatorInterface; /** * Extension supporting the Symfony Validator component in forms. @@ -26,31 +25,26 @@ */ class ValidatorExtension extends AbstractExtension { + /** + * @var ValidatorInterface + */ private $validator; /** - * @param ValidatorInterface|LegacyValidatorInterface $validator + * @param ValidatorInterface $validator * * @throws UnexpectedTypeException If $validator is invalid */ - public function __construct($validator) + public function __construct(ValidatorInterface $validator) { - // 2.5 API - if ($validator instanceof ValidatorInterface) { - $metadata = $validator->getMetadataFor('Symfony\Component\Form\Form'); - // 2.4 API - } elseif ($validator instanceof LegacyValidatorInterface) { - $metadata = $validator->getMetadataFactory()->getMetadataFor('Symfony\Component\Form\Form'); - } else { - throw new UnexpectedTypeException($validator, 'Symfony\Component\Validator\Validator\ValidatorInterface or Symfony\Component\Validator\ValidatorInterface'); - } + /* @var ClassMetadata $metadata */ + $metadata = $validator->getMetadataFor('Symfony\Component\Form\Form'); // Register the form constraints in the validator programmatically. // This functionality is required when using the Form component without // the DIC, where the XML file is loaded automatically. Thus the following // code must be kept synchronized with validation.xml - /* @var $metadata ClassMetadata */ $metadata->addConstraint(new Form()); $metadata->addPropertyConstraint('children', new Valid()); @@ -59,13 +53,7 @@ public function __construct($validator) public function loadTypeGuesser() { - // 2.5 API - if ($this->validator instanceof ValidatorInterface) { - return new ValidatorTypeGuesser($this->validator); - } - - // 2.4 API - return new ValidatorTypeGuesser($this->validator->getMetadataFactory()); + return new ValidatorTypeGuesser($this->validator); } protected function loadTypeExtensions() diff --git a/src/Symfony/Component/Form/Extension/Validator/ValidatorTypeGuesser.php b/src/Symfony/Component/Form/Extension/Validator/ValidatorTypeGuesser.php index faa2ea94f4f28..76f2259ba97e9 100644 --- a/src/Symfony/Component/Form/Extension/Validator/ValidatorTypeGuesser.php +++ b/src/Symfony/Component/Form/Extension/Validator/ValidatorTypeGuesser.php @@ -17,7 +17,7 @@ use Symfony\Component\Form\Guess\ValueGuess; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Mapping\ClassMetadataInterface; -use Symfony\Component\Validator\MetadataFactoryInterface; +use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface; class ValidatorTypeGuesser implements FormTypeGuesserInterface { diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/EventListener/ValidationListenerTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/EventListener/ValidationListenerTest.php index ff08e8ea54c75..f51176c621353 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/EventListener/ValidationListenerTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/EventListener/ValidationListenerTest.php @@ -56,7 +56,7 @@ protected function setUp() { $this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); $this->factory = $this->getMock('Symfony\Component\Form\FormFactoryInterface'); - $this->validator = $this->getMock('Symfony\Component\Validator\ValidatorInterface'); + $this->validator = $this->getMock('Symfony\Component\Validator\Validator\ValidatorInterface'); $this->violationMapper = $this->getMock('Symfony\Component\Form\Extension\Validator\ViolationMapper\ViolationMapperInterface'); $this->listener = new ValidationListener($this->validator, $this->violationMapper); $this->message = 'Message'; @@ -182,31 +182,9 @@ public function testValidateWithEmptyViolationList() public function testValidatorInterfaceSinceSymfony25() { - // Mock of ValidatorInterface since apiVersion 2.5 $validator = $this->getMock('Symfony\Component\Validator\Validator\ValidatorInterface'); $listener = new ValidationListener($validator, $this->violationMapper); $this->assertAttributeSame($validator, 'validator', $listener); } - - /** - * @group legacy - */ - public function testValidatorInterfaceUntilSymfony24() - { - // Mock of ValidatorInterface until apiVersion 2.4 - $validator = $this->getMock('Symfony\Component\Validator\ValidatorInterface'); - - $listener = new ValidationListener($validator, $this->violationMapper); - $this->assertAttributeSame($validator, 'validator', $listener); - } - - /** - * @group legacy - * @expectedException \InvalidArgumentException - */ - public function testInvalidValidatorInterface() - { - new ValidationListener(null, $this->violationMapper); - } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/Type/FormTypeValidatorExtensionTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/Type/FormTypeValidatorExtensionTest.php index 214b8236cb670..400e8d3cc0f02 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/Type/FormTypeValidatorExtensionTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/Type/FormTypeValidatorExtensionTest.php @@ -47,30 +47,12 @@ public function testValidConstraint() public function testValidatorInterfaceSinceSymfony25() { - // Mock of ValidatorInterface since apiVersion 2.5 $validator = $this->getMock('Symfony\Component\Validator\Validator\ValidatorInterface'); $formTypeValidatorExtension = new FormTypeValidatorExtension($validator); $this->assertAttributeSame($validator, 'validator', $formTypeValidatorExtension); } - public function testValidatorInterfaceUntilSymfony24() - { - // Mock of ValidatorInterface until apiVersion 2.4 - $validator = $this->getMock('Symfony\Component\Validator\ValidatorInterface'); - - $formTypeValidatorExtension = new FormTypeValidatorExtension($validator); - $this->assertAttributeSame($validator, 'validator', $formTypeValidatorExtension); - } - - /** - * @expectedException \InvalidArgumentException - */ - public function testInvalidValidatorInterface() - { - new FormTypeValidatorExtension(null); - } - protected function createForm(array $options = array()) { return $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, $options); diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/Type/TypeTestCase.php b/src/Symfony/Component/Form/Tests/Extension/Validator/Type/TypeTestCase.php index f197b19857315..959a385ae0376 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/Type/TypeTestCase.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/Type/TypeTestCase.php @@ -20,11 +20,18 @@ abstract class TypeTestCase extends BaseTypeTestCase protected function setUp() { - $this->validator = $this->getMock('Symfony\Component\Validator\ValidatorInterface'); - $metadataFactory = $this->getMock('Symfony\Component\Validator\MetadataFactoryInterface'); - $this->validator->expects($this->once())->method('getMetadataFactory')->will($this->returnValue($metadataFactory)); - $metadata = $this->getMockBuilder('Symfony\Component\Validator\Mapping\ClassMetadata')->disableOriginalConstructor()->getMock(); - $metadataFactory->expects($this->once())->method('getMetadataFor')->will($this->returnValue($metadata)); + $metadata = $this->getMockBuilder('Symfony\Component\Validator\Mapping\ClassMetadata') + ->disableOriginalConstructor() + ->getMock(); + + $metadata->expects($this->once()) + ->method('addConstraint') + ->willReturn(null); + + $this->validator = $this->getMock('Symfony\Component\Validator\Validator\ValidatorInterface'); + $this->validator->expects($this->once()) + ->method('getMetadataFor') + ->willReturn($metadata); parent::setUp(); } diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorExtensionTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorExtensionTest.php index d85cd863c01ce..cf8c955bb93ce 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorExtensionTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorExtensionTest.php @@ -20,6 +20,7 @@ public function test2Dot5ValidationApi() $validator = $this->getMockBuilder('Symfony\Component\Validator\Validator\RecursiveValidator') ->disableOriginalConstructor() ->getMock(); + $metadata = $this->getMockBuilder('Symfony\Component\Validator\Mapping\ClassMetadata') ->disableOriginalConstructor() ->getMock(); @@ -38,8 +39,7 @@ public function test2Dot5ValidationApi() ->method('addPropertyConstraint') ->with('children', $this->isInstanceOf('Symfony\Component\Validator\Constraints\Valid')); - $validator - ->expects($this->never()) + $validator->expects($this->never()) ->method('getMetadataFactory'); $extension = new ValidatorExtension($validator); diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorTypeGuesserTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorTypeGuesserTest.php index 0e5a24bf6731a..9a6f89be3d57d 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorTypeGuesserTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorTypeGuesserTest.php @@ -51,7 +51,7 @@ class ValidatorTypeGuesserTest extends \PHPUnit_Framework_TestCase protected function setUp() { $this->metadata = new ClassMetadata(self::TEST_CLASS); - $this->metadataFactory = $this->getMock('Symfony\Component\Validator\MetadataFactoryInterface'); + $this->metadataFactory = $this->getMock('Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface'); $this->metadataFactory->expects($this->any()) ->method('getMetadataFor') ->with(self::TEST_CLASS) diff --git a/src/Symfony/Component/Validator/ConstraintValidator.php b/src/Symfony/Component/Validator/ConstraintValidator.php index 3b5d6bc16471b..3bfd0eb40dfe2 100644 --- a/src/Symfony/Component/Validator/ConstraintValidator.php +++ b/src/Symfony/Component/Validator/ConstraintValidator.php @@ -11,9 +11,7 @@ namespace Symfony\Component\Validator; -use Symfony\Component\Validator\Context\ExecutionContextInterface as ExecutionContextInterface2Dot5; -use Symfony\Component\Validator\Violation\ConstraintViolationBuilderInterface; -use Symfony\Component\Validator\Violation\LegacyConstraintViolationBuilder; +use Symfony\Component\Validator\Context\ExecutionContextInterface; /** * Base class for constraint validators. @@ -52,51 +50,6 @@ public function initialize(ExecutionContextInterface $context) $this->context = $context; } - /** - * Wrapper for {@link ExecutionContextInterface::buildViolation} that - * supports the 2.4 context API. - * - * @param string $message The violation message - * @param array $parameters The message parameters - * - * @return ConstraintViolationBuilderInterface The violation builder - * - * @deprecated since version 2.5, to be removed in 3.0. - */ - protected function buildViolation($message, array $parameters = array()) - { - @trigger_error('The '.__METHOD__.' is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED); - - if ($this->context instanceof ExecutionContextInterface2Dot5) { - return $this->context->buildViolation($message, $parameters); - } - - return new LegacyConstraintViolationBuilder($this->context, $message, $parameters); - } - - /** - * Wrapper for {@link ExecutionContextInterface::buildViolation} that - * supports the 2.4 context API. - * - * @param ExecutionContextInterface $context The context to use - * @param string $message The violation message - * @param array $parameters The message parameters - * - * @return ConstraintViolationBuilderInterface The violation builder - * - * @deprecated since version 2.5, to be removed in 3.0. - */ - protected function buildViolationInContext(ExecutionContextInterface $context, $message, array $parameters = array()) - { - @trigger_error('The '.__METHOD__.' is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED); - - if ($context instanceof ExecutionContextInterface2Dot5) { - return $context->buildViolation($message, $parameters); - } - - return new LegacyConstraintViolationBuilder($context, $message, $parameters); - } - /** * Returns a string representation of the type of the value. * diff --git a/src/Symfony/Component/Validator/ConstraintValidatorInterface.php b/src/Symfony/Component/Validator/ConstraintValidatorInterface.php index f7538a1fef619..6c7afbc3e0a12 100644 --- a/src/Symfony/Component/Validator/ConstraintValidatorInterface.php +++ b/src/Symfony/Component/Validator/ConstraintValidatorInterface.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Validator; +use Symfony\Component\Validator\Context\ExecutionContextInterface; + /** * @author Bernhard Schussek * diff --git a/src/Symfony/Component/Validator/ConstraintViolation.php b/src/Symfony/Component/Validator/ConstraintViolation.php index 31b44d23cd3da..bc843ffda1eef 100644 --- a/src/Symfony/Component/Validator/ConstraintViolation.php +++ b/src/Symfony/Component/Validator/ConstraintViolation.php @@ -139,19 +139,6 @@ public function getMessageTemplate() return $this->messageTemplate; } - /** - * {@inheritdoc} - * - * @deprecated since version 2.7, to be removed in 3.0. - * Use getParameters() instead - */ - public function getMessageParameters() - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 2.7, to be removed in 3.0. Use the ConstraintViolation::getParameters() method instead.', E_USER_DEPRECATED); - - return $this->parameters; - } - /** * Alias of {@link getMessageParameters()}. */ @@ -160,19 +147,6 @@ public function getParameters() return $this->parameters; } - /** - * {@inheritdoc} - * - * @deprecated since version 2.7, to be removed in 3.0. - * Use getPlural() instead - */ - public function getMessagePluralization() - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 2.7, to be removed in 3.0. Use the ConstraintViolation::getPlural() method instead.', E_USER_DEPRECATED); - - return $this->plural; - } - /** * Alias of {@link getMessagePluralization()}. */ diff --git a/src/Symfony/Component/Validator/ConstraintViolationInterface.php b/src/Symfony/Component/Validator/ConstraintViolationInterface.php index c0577160245b4..e9566c4473b80 100644 --- a/src/Symfony/Component/Validator/ConstraintViolationInterface.php +++ b/src/Symfony/Component/Validator/ConstraintViolationInterface.php @@ -59,40 +59,6 @@ public function getMessage(); */ public function getMessageTemplate(); - /** - * Returns the parameters to be inserted into the raw violation message. - * - * @return array A possibly empty list of parameters indexed by the names - * that appear in the message template. - * - * @see getMessageTemplate() - * - * @api - * - * @deprecated since version 2.7, to be replaced by getParameters() in 3.0. - */ - public function getMessageParameters(); - - /** - * Returns a number for pluralizing the violation message. - * - * For example, the message template could have different translation based - * on a parameter "choices": - * - * - * - * This method returns the value of the parameter for choosing the right - * pluralization form (in this case "choices"). - * - * @return int|null The number to use to pluralize of the message. - * - * @deprecated since version 2.7, to be replaced by getPlural() in 3.0. - */ - public function getMessagePluralization(); - /** * Returns the root element of the validation. * diff --git a/src/Symfony/Component/Validator/Constraints/Callback.php b/src/Symfony/Component/Validator/Constraints/Callback.php index d1d05fa26b04a..6ff2a8f37f2c6 100644 --- a/src/Symfony/Component/Validator/Constraints/Callback.php +++ b/src/Symfony/Component/Validator/Constraints/Callback.php @@ -47,16 +47,9 @@ public function __construct($options = null) $options = $options['value']; } - if (is_array($options) && isset($options['methods'])) { - @trigger_error('The "methods" option of the '.__CLASS__.' class is deprecated since version 2.4 and will be removed in 3.0. Use the "callback" option instead.', E_USER_DEPRECATED); - } - if (is_array($options) && !isset($options['callback']) && !isset($options['methods']) && !isset($options['groups'])) { if (is_callable($options) || !$options) { $options = array('callback' => $options); - } else { - // @deprecated, to be removed in 3.0 - $options = array('methods' => $options); } } diff --git a/src/Symfony/Component/Validator/Constraints/Collection/Optional.php b/src/Symfony/Component/Validator/Constraints/Collection/Optional.php deleted file mode 100644 index 68471f925579a..0000000000000 --- a/src/Symfony/Component/Validator/Constraints/Collection/Optional.php +++ /dev/null @@ -1,29 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator\Constraints\Collection; - -@trigger_error('The '.__NAMESPACE__.'\Optional class is deprecated since version 2.3 and will be removed in 3.0. Use the Symfony\Component\Validator\Constraints\Optional class instead.', E_USER_DEPRECATED); - -use Symfony\Component\Validator\Constraints\Optional as BaseOptional; - -/** - * @Annotation - * @Target({"PROPERTY", "METHOD", "ANNOTATION"}) - * - * @author Bernhard Schussek - * - * @deprecated since version 2.3, to be removed in 3.0. - * Use {@link \Symfony\Component\Validator\Constraints\Optional} instead. - */ -class Optional extends BaseOptional -{ -} diff --git a/src/Symfony/Component/Validator/Constraints/Collection/Required.php b/src/Symfony/Component/Validator/Constraints/Collection/Required.php deleted file mode 100644 index 4b062bb558db7..0000000000000 --- a/src/Symfony/Component/Validator/Constraints/Collection/Required.php +++ /dev/null @@ -1,29 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator\Constraints\Collection; - -@trigger_error('The '.__NAMESPACE__.'\Required class is deprecated since version 2.3 and will be removed in 3.0. Use the Symfony\Component\Validator\Constraints\Required class instead.', E_USER_DEPRECATED); - -use Symfony\Component\Validator\Constraints\Required as BaseRequired; - -/** - * @Annotation - * @Target({"PROPERTY", "METHOD", "ANNOTATION"}) - * - * @author Bernhard Schussek - * - * @deprecated since version 2.3, to be removed in 3.0. - * Use {@link \Symfony\Component\Validator\Constraints\Required} instead. - */ -class Required extends BaseRequired -{ -} diff --git a/src/Symfony/Component/Validator/Constraints/False.php b/src/Symfony/Component/Validator/Constraints/False.php deleted file mode 100644 index 1e103ade514d6..0000000000000 --- a/src/Symfony/Component/Validator/Constraints/False.php +++ /dev/null @@ -1,26 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator\Constraints; - -@trigger_error('The '.__NAMESPACE__.'\False class is deprecated since version 2.7 and will be removed in 3.0. Use the IsFalse class in the same namespace instead.', E_USER_DEPRECATED); - -/** - * @Annotation - * @Target({"PROPERTY", "METHOD", "ANNOTATION"}) - * - * @author Bernhard Schussek - * - * @deprecated since version 2.7, to be removed in 3.0. Use IsFalse instead. - */ -class False extends IsFalse -{ -} diff --git a/src/Symfony/Component/Validator/Constraints/FalseValidator.php b/src/Symfony/Component/Validator/Constraints/FalseValidator.php deleted file mode 100644 index 9614c3037fe92..0000000000000 --- a/src/Symfony/Component/Validator/Constraints/FalseValidator.php +++ /dev/null @@ -1,23 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator\Constraints; - -@trigger_error('The '.__NAMESPACE__.'\FalseValidator class is deprecated since version 2.7 and will be removed in 3.0. Use the IsFalseValidator class in the same namespace instead.', E_USER_DEPRECATED); - -/** - * @author Bernhard Schussek - * - * @deprecated since version 2.7, to be removed in 3.0. Use IsFalseValidator instead. - */ -class FalseValidator extends IsFalseValidator -{ -} diff --git a/src/Symfony/Component/Validator/Constraints/GroupSequence.php b/src/Symfony/Component/Validator/Constraints/GroupSequence.php index a28a442246265..40e5021c2a068 100644 --- a/src/Symfony/Component/Validator/Constraints/GroupSequence.php +++ b/src/Symfony/Component/Validator/Constraints/GroupSequence.php @@ -11,8 +11,6 @@ namespace Symfony\Component\Validator\Constraints; -use Symfony\Component\Validator\Exception\OutOfBoundsException; - /** * A sequence of validation groups. * @@ -55,10 +53,8 @@ * @author Bernhard Schussek * * @api - * - * Implementing \ArrayAccess, \IteratorAggregate and \Countable is @deprecated since 2.5 and will be removed in 3.0. */ -class GroupSequence implements \ArrayAccess, \IteratorAggregate, \Countable +class GroupSequence { /** * The groups in the sequence. @@ -93,121 +89,4 @@ public function __construct(array $groups) // Support for Doctrine annotations $this->groups = isset($groups['value']) ? $groups['value'] : $groups; } - - /** - * Returns an iterator for this group. - * - * Implemented for backwards compatibility with Symfony < 2.5. - * - * @return \Traversable The iterator - * - * @see \IteratorAggregate::getIterator() - * @deprecated since version 2.5, to be removed in 3.0. - */ - public function getIterator() - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED); - - return new \ArrayIterator($this->groups); - } - - /** - * 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 since version 2.5, to be removed in 3.0. - */ - public function offsetExists($offset) - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED); - - return isset($this->groups[$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 since version 2.5, to be removed in 3.0. - */ - public function offsetGet($offset) - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED); - - if (!isset($this->groups[$offset])) { - throw new OutOfBoundsException(sprintf( - 'The offset "%s" does not exist.', - $offset - )); - } - - return $this->groups[$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 since version 2.5, to be removed in 3.0. - */ - public function offsetSet($offset, $value) - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED); - - if (null !== $offset) { - $this->groups[$offset] = $value; - - return; - } - - $this->groups[] = $value; - } - - /** - * Removes the group at the given offset. - * - * Implemented for backwards compatibility with Symfony < 2.5. - * - * @param int $offset The offset - * - * @deprecated since version 2.5, to be removed in 3.0. - */ - public function offsetUnset($offset) - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED); - - unset($this->groups[$offset]); - } - - /** - * Returns the number of groups in the sequence. - * - * Implemented for backwards compatibility with Symfony < 2.5. - * - * @return int The number of groups - * - * @deprecated since version 2.5, to be removed in 3.0. - */ - public function count() - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED); - - return count($this->groups); - } } diff --git a/src/Symfony/Component/Validator/Constraints/Iban.php b/src/Symfony/Component/Validator/Constraints/Iban.php index 9c4d3838fa0f8..bcb30655aa44b 100644 --- a/src/Symfony/Component/Validator/Constraints/Iban.php +++ b/src/Symfony/Component/Validator/Constraints/Iban.php @@ -23,21 +23,15 @@ */ class Iban extends Constraint { - /** @deprecated, to be removed in 3.0. */ - const TOO_SHORT_ERROR = '88e5e319-0aeb-4979-a27e-3d9ce0c16166'; const INVALID_COUNTRY_CODE_ERROR = 'de78ee2c-bd50-44e2-aec8-3d8228aeadb9'; const INVALID_CHARACTERS_ERROR = '8d3d85e4-784f-4719-a5bc-d9e40d45a3a5'; - /** @deprecated, to be removed in 3.0. */ - const INVALID_CASE_ERROR = 'f4bf62fe-03ec-42af-a53b-68e21b1e7274'; const CHECKSUM_FAILED_ERROR = 'b9401321-f9bf-4dcb-83c1-f31094440795'; const INVALID_FORMAT_ERROR = 'c8d318f1-2ecc-41ba-b983-df70d225cf5a'; const NOT_SUPPORTED_COUNTRY_CODE_ERROR = 'e2c259f3-4b46-48e6-b72e-891658158ec8'; protected static $errorNames = array( - self::TOO_SHORT_ERROR => 'TOO_SHORT_ERROR', self::INVALID_COUNTRY_CODE_ERROR => 'INVALID_COUNTRY_CODE_ERROR', self::INVALID_CHARACTERS_ERROR => 'INVALID_CHARACTERS_ERROR', - self::INVALID_CASE_ERROR => 'INVALID_CASE_ERROR', self::CHECKSUM_FAILED_ERROR => 'CHECKSUM_FAILED_ERROR', self::INVALID_FORMAT_ERROR => 'INVALID_FORMAT_ERROR', self::NOT_SUPPORTED_COUNTRY_CODE_ERROR => 'NOT_SUPPORTED_COUNTRY_CODE_ERROR', diff --git a/src/Symfony/Component/Validator/Constraints/Isbn.php b/src/Symfony/Component/Validator/Constraints/Isbn.php index f1e83b99ea02a..615feb66416d4 100644 --- a/src/Symfony/Component/Validator/Constraints/Isbn.php +++ b/src/Symfony/Component/Validator/Constraints/Isbn.php @@ -43,20 +43,6 @@ class Isbn extends Constraint public $type; public $message; - /** - * @deprecated since version 2.5, to be removed in 3.0. Use option "type" instead. - * - * @var bool - */ - public $isbn10 = false; - - /** - * @deprecated since version 2.5, to be removed in 3.0. Use option "type" instead. - * - * @var bool - */ - public $isbn13 = false; - /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/Validator/Constraints/IsbnValidator.php b/src/Symfony/Component/Validator/Constraints/IsbnValidator.php index aaf52dc561c3c..3d4695281dba6 100644 --- a/src/Symfony/Component/Validator/Constraints/IsbnValidator.php +++ b/src/Symfony/Component/Validator/Constraints/IsbnValidator.php @@ -47,16 +47,6 @@ public function validate($value, Constraint $constraint) $value = (string) $value; $canonical = str_replace('-', '', $value); - if (null === $constraint->type) { - if ($constraint->isbn10 && !$constraint->isbn13) { - @trigger_error('The "isbn10" option of the Isbn constraint is deprecated since version 2.5 and will be removed in 3.0. Use the "type" option instead.', E_USER_DEPRECATED); - $constraint->type = 'isbn10'; - } elseif ($constraint->isbn13 && !$constraint->isbn10) { - @trigger_error('The "isbn13" option of the Isbn constraint is deprecated since version 2.5 and will be removed in 3.0. Use the "type" option instead.', E_USER_DEPRECATED); - $constraint->type = 'isbn13'; - } - } - // Explicitly validate against ISBN-10 if ('isbn10' === $constraint->type) { if (true !== ($code = $this->validateIsbn10($canonical))) { diff --git a/src/Symfony/Component/Validator/Constraints/Null.php b/src/Symfony/Component/Validator/Constraints/Null.php deleted file mode 100644 index 705d93fc41f3c..0000000000000 --- a/src/Symfony/Component/Validator/Constraints/Null.php +++ /dev/null @@ -1,26 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator\Constraints; - -@trigger_error('The '.__NAMESPACE__.'\Null class is deprecated since version 2.7 and will be removed in 3.0. Use the IsNull class in the same namespace instead.', E_USER_DEPRECATED); - -/** - * @Annotation - * @Target({"PROPERTY", "METHOD", "ANNOTATION"}) - * - * @author Bernhard Schussek - * - * @deprecated since version 2.7, to be removed in 3.0. Use IsNull instead. - */ -class Null extends IsNull -{ -} diff --git a/src/Symfony/Component/Validator/Constraints/NullValidator.php b/src/Symfony/Component/Validator/Constraints/NullValidator.php deleted file mode 100644 index bd17eab528c20..0000000000000 --- a/src/Symfony/Component/Validator/Constraints/NullValidator.php +++ /dev/null @@ -1,23 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator\Constraints; - -@trigger_error('The '.__NAMESPACE__.'\NullValidator class is deprecated since version 2.7 and will be removed in 3.0. Use the IsNullValidator class in the same namespace instead.', E_USER_DEPRECATED); - -/** - * @author Bernhard Schussek - * - * @deprecated since version 2.7, to be removed in 3.0. Use IsNullValidator instead. - */ -class NullValidator extends IsNullValidator -{ -} diff --git a/src/Symfony/Component/Validator/Constraints/Range.php b/src/Symfony/Component/Validator/Constraints/Range.php index 26d2546cc2458..199163b3ab37f 100644 --- a/src/Symfony/Component/Validator/Constraints/Range.php +++ b/src/Symfony/Component/Validator/Constraints/Range.php @@ -28,24 +28,6 @@ class Range extends Constraint const TOO_HIGH_ERROR = '2d28afcb-e32e-45fb-a815-01c431a86a69'; const TOO_LOW_ERROR = '76454e69-502c-46c5-9643-f447d837c4d5'; - /** - * @deprecated Deprecated since version 2.8, to be removed in 3.0. Use - * {@link INVALID_CHARACTERS_ERROR} instead. - */ - const INVALID_VALUE_ERROR = self::INVALID_CHARACTERS_ERROR; - - /** - * @deprecated Deprecated since version 2.8, to be removed in 3.0. Use - * {@link TOO_HIGH_ERROR} instead. - */ - const BEYOND_RANGE_ERROR = self::TOO_HIGH_ERROR; - - /** - * @deprecated Deprecated since version 2.8, to be removed in 3.0. Use - * {@link TOO_LOW_ERROR} instead. - */ - const BELOW_RANGE_ERROR = self::TOO_LOW_ERROR; - protected static $errorNames = array( self::INVALID_CHARACTERS_ERROR => 'INVALID_CHARACTERS_ERROR', self::TOO_HIGH_ERROR => 'TOO_HIGH_ERROR', diff --git a/src/Symfony/Component/Validator/Constraints/True.php b/src/Symfony/Component/Validator/Constraints/True.php deleted file mode 100644 index b9efff375e1bf..0000000000000 --- a/src/Symfony/Component/Validator/Constraints/True.php +++ /dev/null @@ -1,26 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator\Constraints; - -@trigger_error('The '.__NAMESPACE__.'\True class is deprecated since version 2.7 and will be removed in 3.0. Use the IsTrue class in the same namespace instead.', E_USER_DEPRECATED); - -/** - * @Annotation - * @Target({"PROPERTY", "METHOD", "ANNOTATION"}) - * - * @author Bernhard Schussek - * - * @deprecated since version 2.7, to be removed in 3.0. Use IsTrue instead. - */ -class True extends IsTrue -{ -} diff --git a/src/Symfony/Component/Validator/Constraints/TrueValidator.php b/src/Symfony/Component/Validator/Constraints/TrueValidator.php deleted file mode 100644 index 14d879808da02..0000000000000 --- a/src/Symfony/Component/Validator/Constraints/TrueValidator.php +++ /dev/null @@ -1,23 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator\Constraints; - -@trigger_error('The '.__NAMESPACE__.'\TrueValidator class is deprecated since version 2.7 and will be removed in 3.0. Use the IsTrueValidator class in the same namespace instead.', E_USER_DEPRECATED); - -/** - * @author Bernhard Schussek - * - * @deprecated since version 2.7, to be removed in 3.0. Use IsTrueValidator instead. - */ -class TrueValidator extends IsTrueValidator -{ -} diff --git a/src/Symfony/Component/Validator/Constraints/UuidValidator.php b/src/Symfony/Component/Validator/Constraints/UuidValidator.php index 08f9e27b736c8..e3c856f44b41e 100644 --- a/src/Symfony/Component/Validator/Constraints/UuidValidator.php +++ b/src/Symfony/Component/Validator/Constraints/UuidValidator.php @@ -14,7 +14,6 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; -use Symfony\Component\Validator\Constraints\Deprecated\UuidValidator as Deprecated; use Symfony\Component\Validator\Exception\UnexpectedTypeException; /** @@ -57,21 +56,6 @@ class UuidValidator extends ConstraintValidator const LOOSE_MAX_LENGTH = 39; const LOOSE_FIRST_HYPHEN_POSITION = 4; - /** - * @deprecated since version 2.6, to be removed in 3.0 - */ - const STRICT_PATTERN = '/^[a-f0-9]{8}-[a-f0-9]{4}-[%s][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/i'; - - /** - * @deprecated since version 2.6, to be removed in 3.0 - */ - const LOOSE_PATTERN = '/^[a-f0-9]{4}(?:-?[a-f0-9]{4}){7}$/i'; - - /** - * @deprecated since version 2.6, to be removed in 3.0 - */ - const STRICT_UUID_LENGTH = 36; - /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/Validator/Constraints/Valid.php b/src/Symfony/Component/Validator/Constraints/Valid.php index 9fc0015632822..d82c93428e83d 100644 --- a/src/Symfony/Component/Validator/Constraints/Valid.php +++ b/src/Symfony/Component/Validator/Constraints/Valid.php @@ -40,10 +40,6 @@ public function __construct($options = null) )); } - if (is_array($options) && array_key_exists('deep', $options)) { - @trigger_error('The "deep" option for the Valid constraint is deprecated since version 2.5 and will be removed in 3.0. When traversing arrays, nested arrays are always traversed. When traversing nested objects, their traversal strategy is used.', E_USER_DEPRECATED); - } - parent::__construct($options); } } diff --git a/src/Symfony/Component/Validator/Context/ExecutionContext.php b/src/Symfony/Component/Validator/Context/ExecutionContext.php index 722bcc947d2f4..c9b5c7292c1c9 100644 --- a/src/Symfony/Component/Validator/Context/ExecutionContext.php +++ b/src/Symfony/Component/Validator/Context/ExecutionContext.php @@ -14,14 +14,12 @@ use Symfony\Component\Translation\TranslatorInterface; use Symfony\Component\Validator\ClassBasedInterface; use Symfony\Component\Validator\Constraint; -use Symfony\Component\Validator\Constraints\Valid; use Symfony\Component\Validator\ConstraintViolation; use Symfony\Component\Validator\ConstraintViolationList; use Symfony\Component\Validator\Mapping\MetadataInterface; use Symfony\Component\Validator\Mapping\PropertyMetadataInterface; use Symfony\Component\Validator\Util\PropertyPath; use Symfony\Component\Validator\Validator\ValidatorInterface; -use Symfony\Component\Validator\ValidatorInterface as LegacyValidatorInterface; use Symfony\Component\Validator\Violation\ConstraintViolationBuilder; /** @@ -183,25 +181,8 @@ public function setConstraint(Constraint $constraint) /** * {@inheritdoc} */ - public function addViolation($message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null) + public function addViolation($message, array $parameters = array()) { - // The parameters $invalidValue and following are ignored by the new - // 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); - - $this - ->buildViolation($message, $parameters) - ->setInvalidValue($invalidValue) - ->setPlural($plural) - ->setCode($code) - ->addViolation() - ; - - return; - } - $this->violations->add(new ConstraintViolation( $this->translator->trans($message, $parameters, $this->translationDomain), $message, @@ -313,103 +294,6 @@ public function getPropertyPath($subPath = '') return PropertyPath::append($this->propertyPath, $subPath); } - /** - * {@inheritdoc} - */ - 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) - ->atPath($subPath) - ->setInvalidValue($invalidValue) - ->setPlural($plural) - ->setCode($code) - ->addViolation() - ; - - return; - } - - $this - ->buildViolation($message, $parameters) - ->atPath($subPath) - ->addViolation() - ; - } - - /** - * {@inheritdoc} - */ - public function validate($value, $subPath = '', $groups = null, $traverse = false, $deep = false) - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0. Use the '.__CLASS__.'::getValidator() method instead.', E_USER_DEPRECATED); - - if (is_array($value)) { - // The $traverse flag is ignored for arrays - $constraint = new Valid(array('traverse' => true, 'deep' => $deep)); - - return $this - ->getValidator() - ->inContext($this) - ->atPath($subPath) - ->validate($value, $constraint, $groups) - ; - } - - if ($traverse && $value instanceof \Traversable) { - $constraint = new Valid(array('traverse' => true, 'deep' => $deep)); - - return $this - ->getValidator() - ->inContext($this) - ->atPath($subPath) - ->validate($value, $constraint, $groups) - ; - } - - return $this - ->getValidator() - ->inContext($this) - ->atPath($subPath) - ->validate($value, null, $groups) - ; - } - - /** - * {@inheritdoc} - */ - 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__.'::getValidator() method instead.', E_USER_DEPRECATED); - - return $this - ->getValidator() - ->inContext($this) - ->atPath($subPath) - ->validate($value, $constraints, $groups) - ; - } - - /** - * {@inheritdoc} - */ - 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); - - $validator = $this->getValidator(); - - if ($validator instanceof LegacyValidatorInterface) { - return $validator->getMetadataFactory(); - } - - // The ValidatorInterface extends from the deprecated MetadataFactoryInterface, so return it when we don't have the factory instance itself - return $validator; - } - /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/Validator/Context/ExecutionContextInterface.php b/src/Symfony/Component/Validator/Context/ExecutionContextInterface.php index 2ef80b66f041a..a98e29d81b7b1 100644 --- a/src/Symfony/Component/Validator/Context/ExecutionContextInterface.php +++ b/src/Symfony/Component/Validator/Context/ExecutionContextInterface.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Validator\Context; use Symfony\Component\Validator\Constraint; -use Symfony\Component\Validator\ExecutionContextInterface as LegacyExecutionContextInterface; use Symfony\Component\Validator\Mapping\MetadataInterface; use Symfony\Component\Validator\Validator\ValidatorInterface; use Symfony\Component\Validator\Violation\ConstraintViolationBuilderInterface; @@ -60,7 +59,7 @@ * * @author Bernhard Schussek */ -interface ExecutionContextInterface extends LegacyExecutionContextInterface +interface ExecutionContextInterface { /** * Returns a builder for adding a violation with extended information. diff --git a/src/Symfony/Component/Validator/Context/LegacyExecutionContext.php b/src/Symfony/Component/Validator/Context/LegacyExecutionContext.php deleted file mode 100644 index f52b359fb39ca..0000000000000 --- a/src/Symfony/Component/Validator/Context/LegacyExecutionContext.php +++ /dev/null @@ -1,55 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator\Context; - -@trigger_error('The '.__NAMESPACE__.'\LegacyExecutionContext class is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED); - -use Symfony\Component\Translation\TranslatorInterface; -use Symfony\Component\Validator\MetadataFactoryInterface; -use Symfony\Component\Validator\Validator\ValidatorInterface; - -/** - * An execution context that is compatible with the legacy API (< 2.5). - * - * @since 2.5 - * - * @author Bernhard Schussek - * - * @deprecated since version 2.5, to be removed in 3.0. - */ -class LegacyExecutionContext extends ExecutionContext -{ - /** - * @var MetadataFactoryInterface - */ - private $metadataFactory; - - /** - * Creates a new context. - * - * @see ExecutionContext::__construct() - * - * @internal Called by {@link LegacyExecutionContextFactory}. Should not be used - * in user code. - */ - public function __construct(ValidatorInterface $validator, $root, MetadataFactoryInterface $metadataFactory, TranslatorInterface $translator, $translationDomain = null) - { - parent::__construct( - $validator, - $root, - $translator, - $translationDomain - ); - - $this->metadataFactory = $metadataFactory; - } -} diff --git a/src/Symfony/Component/Validator/Context/LegacyExecutionContextFactory.php b/src/Symfony/Component/Validator/Context/LegacyExecutionContextFactory.php deleted file mode 100644 index c110644e99c1b..0000000000000 --- a/src/Symfony/Component/Validator/Context/LegacyExecutionContextFactory.php +++ /dev/null @@ -1,77 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator\Context; - -@trigger_error('The '.__NAMESPACE__.'\LegacyExecutionContextFactory class is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED); - -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 - * - * @deprecated since version 2.5, to be removed in 3.0. - */ -class LegacyExecutionContextFactory implements ExecutionContextFactoryInterface -{ - /** - * @var MetadataFactoryInterface - */ - private $metadataFactory; - - /** - * @var TranslatorInterface - */ - private $translator; - - /** - * @var string|null - */ - private $translationDomain; - - /** - * Creates a new context factory. - * - * @param MetadataFactoryInterface $metadataFactory The metadata factory - * @param TranslatorInterface $translator The translator - * @param string|null $translationDomain The translation domain - * to use for translating - * violation messages - */ - public function __construct(MetadataFactoryInterface $metadataFactory, TranslatorInterface $translator, $translationDomain = null) - { - $this->metadataFactory = $metadataFactory; - $this->translator = $translator; - $this->translationDomain = $translationDomain; - } - - /** - * {@inheritdoc} - */ - public function createContext(ValidatorInterface $validator, $root) - { - return new LegacyExecutionContext( - $validator, - $root, - $this->metadataFactory, - $this->translator, - $this->translationDomain - ); - } -} diff --git a/src/Symfony/Component/Validator/DefaultTranslator.php b/src/Symfony/Component/Validator/DefaultTranslator.php deleted file mode 100644 index 85853d8d858ce..0000000000000 --- a/src/Symfony/Component/Validator/DefaultTranslator.php +++ /dev/null @@ -1,171 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator; - -@trigger_error('The class '.__NAMESPACE__.'\DefaultTranslator is deprecated since version 2.7 and will be removed in 3.0. Use Symfony\Component\Translation\IdentityTranslator instead.', E_USER_DEPRECATED); - -use Symfony\Component\Translation\TranslatorInterface; -use Symfony\Component\Validator\Exception\BadMethodCallException; -use Symfony\Component\Validator\Exception\InvalidArgumentException; - -/** - * Simple translator implementation that simply replaces the parameters in - * the message IDs. - * - * Example usage: - * - * $translator = new DefaultTranslator(); - * - * echo $translator->trans( - * 'This is a {{ var }}.', - * array('{{ var }}' => 'donkey') - * ); - * - * // -> This is a donkey. - * - * echo $translator->transChoice( - * 'This is {{ count }} donkey.|These are {{ count }} donkeys.', - * 3, - * array('{{ count }}' => 'three') - * ); - * - * // -> These are three donkeys. - * - * This translator does not support message catalogs, translation domains or - * locales. Instead, it implements a subset of the capabilities of - * {@link \Symfony\Component\Translation\Translator} and can be used in places - * where translation is not required by default but should be optional. - * - * @deprecated since version 2.7, to be removed in 3.0. Use Symfony\Component\Translation\IdentityTranslator instead. - * - * @author Bernhard Schussek - */ -class DefaultTranslator implements TranslatorInterface -{ - /** - * Interpolates the given message. - * - * Parameters are replaced in the message in the same manner that - * {@link strtr()} uses. - * - * Example usage: - * - * $translator = new DefaultTranslator(); - * - * echo $translator->trans( - * 'This is a {{ var }}.', - * array('{{ var }}' => 'donkey') - * ); - * - * // -> This is a donkey. - * - * @param string $id The message id - * @param array $parameters An array of parameters for the message - * @param string $domain Ignored - * @param string $locale Ignored - * - * @return string The interpolated string - */ - public function trans($id, array $parameters = array(), $domain = null, $locale = null) - { - return strtr($id, $parameters); - } - - /** - * Interpolates the given choice message by choosing a variant according to a number. - * - * The variants are passed in the message ID using the format - * "|". "" is chosen if the passed $number is - * exactly 1. "" is chosen otherwise. - * - * This format is consistent with the format supported by - * {@link \Symfony\Component\Translation\Translator}, but it does not - * have the same expressiveness. While Translator supports intervals in - * message translations, which are needed for languages other than English, - * this translator does not. You should use Translator or a custom - * implementation of {@link \Symfony\Component\Translation\TranslatorInterface} if you need this or similar - * functionality. - * - * Example usage: - * - * echo $translator->transChoice( - * 'This is {{ count }} donkey.|These are {{ count }} donkeys.', - * 0, - * array('{{ count }}' => 0) - * ); - * - * // -> These are 0 donkeys. - * - * echo $translator->transChoice( - * 'This is {{ count }} donkey.|These are {{ count }} donkeys.', - * 1, - * array('{{ count }}' => 1) - * ); - * - * // -> This is 1 donkey. - * - * echo $translator->transChoice( - * 'This is {{ count }} donkey.|These are {{ count }} donkeys.', - * 3, - * array('{{ count }}' => 3) - * ); - * - * // -> These are 3 donkeys. - * - * @param string $id The message id - * @param int $number The number to use to find the index of the message - * @param array $parameters An array of parameters for the message - * @param string $domain Ignored - * @param string $locale Ignored - * - * @return string The translated string - * - * @throws InvalidArgumentException If the message id does not have the format - * "singular|plural". - */ - public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null) - { - $ids = explode('|', $id); - - if (1 == $number) { - return strtr($ids[0], $parameters); - } - - if (!isset($ids[1])) { - throw new InvalidArgumentException(sprintf('The message "%s" cannot be pluralized, because it is missing a plural (e.g. "There is one apple|There are %%count%% apples").', $id)); - } - - return strtr($ids[1], $parameters); - } - - /** - * Not supported. - * - * @param string $locale The locale - * - * @throws BadMethodCallException - */ - public function setLocale($locale) - { - throw new BadMethodCallException('Unsupported method.'); - } - - /** - * Returns the locale of the translator. - * - * @return string Always returns 'en' - */ - public function getLocale() - { - return 'en'; - } -} diff --git a/src/Symfony/Component/Validator/ExecutionContext.php b/src/Symfony/Component/Validator/ExecutionContext.php deleted file mode 100644 index 5875e94ef45d7..0000000000000 --- a/src/Symfony/Component/Validator/ExecutionContext.php +++ /dev/null @@ -1,295 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator; - -@trigger_error('The '.__NAMESPACE__.'\ExecutionContext class is deprecated since version 2.5 and will be removed in 3.0. Use the Symfony\Component\Validator\Context\ExecutionContext class instead.', E_USER_DEPRECATED); - -use Symfony\Component\Translation\TranslatorInterface; - -/** - * Default implementation of {@link ExecutionContextInterface}. - * - * This class is immutable by design. - * - * @author Fabien Potencier - * @author Bernhard Schussek - * - * @deprecated since version 2.5, to be removed in 3.0. - * Use {@link Context\ExecutionContext} instead. - */ -class ExecutionContext implements ExecutionContextInterface -{ - /** - * @var GlobalExecutionContextInterface - */ - private $globalContext; - - /** - * @var TranslatorInterface - */ - private $translator; - - /** - * @var null|string - */ - private $translationDomain; - - /** - * @var MetadataInterface - */ - private $metadata; - - /** - * @var mixed - */ - private $value; - - /** - * @var string - */ - private $group; - - /** - * @var string - */ - private $propertyPath; - - /** - * Creates a new execution context. - * - * @param GlobalExecutionContextInterface $globalContext The global context storing node-independent state. - * @param TranslatorInterface $translator The translator for translating violation messages. - * @param null|string $translationDomain The domain of the validation messages. - * @param MetadataInterface $metadata The metadata of the validated node. - * @param mixed $value The value of the validated node. - * @param string $group The current validation group. - * @param string $propertyPath The property path to the current node. - */ - public function __construct(GlobalExecutionContextInterface $globalContext, TranslatorInterface $translator, $translationDomain = null, MetadataInterface $metadata = null, $value = null, $group = null, $propertyPath = '') - { - if (null === $group) { - $group = Constraint::DEFAULT_GROUP; - } - - $this->globalContext = $globalContext; - $this->translator = $translator; - $this->translationDomain = $translationDomain; - $this->metadata = $metadata; - $this->value = $value; - $this->propertyPath = $propertyPath; - $this->group = $group; - } - - /** - * {@inheritdoc} - */ - public function addViolation($message, array $params = array(), $invalidValue = null, $plural = null, $code = null) - { - if (null === $plural) { - $translatedMessage = $this->translator->trans($message, $params, $this->translationDomain); - } else { - try { - $translatedMessage = $this->translator->transChoice($message, $plural, $params, $this->translationDomain); - } catch (\InvalidArgumentException $e) { - $translatedMessage = $this->translator->trans($message, $params, $this->translationDomain); - } - } - - $this->globalContext->getViolations()->add(new ConstraintViolation( - $translatedMessage, - $message, - $params, - $this->globalContext->getRoot(), - $this->propertyPath, - // check using func_num_args() to allow passing null values - func_num_args() >= 3 ? $invalidValue : $this->value, - $plural, - $code - )); - } - - /** - * {@inheritdoc} - */ - public function addViolationAt($subPath, $message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null) - { - $this->globalContext->getViolations()->add(new ConstraintViolation( - null === $plural - ? $this->translator->trans($message, $parameters, $this->translationDomain) - : $this->translator->transChoice($message, $plural, $parameters, $this->translationDomain), - $message, - $parameters, - $this->globalContext->getRoot(), - $this->getPropertyPath($subPath), - // check using func_num_args() to allow passing null values - func_num_args() >= 4 ? $invalidValue : $this->value, - $plural, - $code - )); - } - - /** - * {@inheritdoc} - */ - public function getViolations() - { - return $this->globalContext->getViolations(); - } - - /** - * {@inheritdoc} - */ - public function getRoot() - { - return $this->globalContext->getRoot(); - } - - /** - * {@inheritdoc} - */ - public function getPropertyPath($subPath = '') - { - if ('' != $subPath && '' !== $this->propertyPath && '[' !== $subPath[0]) { - return $this->propertyPath.'.'.$subPath; - } - - return $this->propertyPath.$subPath; - } - - /** - * {@inheritdoc} - */ - public function getClassName() - { - if ($this->metadata instanceof ClassBasedInterface) { - return $this->metadata->getClassName(); - } - } - - /** - * {@inheritdoc} - */ - public function getPropertyName() - { - if ($this->metadata instanceof PropertyMetadataInterface) { - return $this->metadata->getPropertyName(); - } - } - - /** - * {@inheritdoc} - */ - public function getValue() - { - return $this->value; - } - - /** - * {@inheritdoc} - */ - public function getGroup() - { - return $this->group; - } - - /** - * {@inheritdoc} - */ - public function getMetadata() - { - return $this->metadata; - } - - /** - * {@inheritdoc} - */ - public function getMetadataFor($value) - { - return $this->globalContext->getMetadataFactory()->getMetadataFor($value); - } - - /** - * {@inheritdoc} - */ - public function validate($value, $subPath = '', $groups = null, $traverse = false, $deep = false) - { - $propertyPath = $this->getPropertyPath($subPath); - - foreach ($this->resolveGroups($groups) as $group) { - $this->globalContext->getVisitor()->validate($value, $group, $propertyPath, $traverse, $deep); - } - } - - /** - * {@inheritdoc} - */ - public function validateValue($value, $constraints, $subPath = '', $groups = null) - { - $constraints = is_array($constraints) ? $constraints : array($constraints); - - if (null === $groups && '' === $subPath) { - $context = clone $this; - $context->value = $value; - $context->executeConstraintValidators($value, $constraints); - - return; - } - - $propertyPath = $this->getPropertyPath($subPath); - - foreach ($this->resolveGroups($groups) as $group) { - $context = clone $this; - $context->value = $value; - $context->group = $group; - $context->propertyPath = $propertyPath; - $context->executeConstraintValidators($value, $constraints); - } - } - - /** - * {@inheritdoc} - */ - public function getMetadataFactory() - { - return $this->globalContext->getMetadataFactory(); - } - - /** - * Executes the validators of the given constraints for the given value. - * - * @param mixed $value The value to validate. - * @param Constraint[] $constraints The constraints to match against. - */ - private function executeConstraintValidators($value, array $constraints) - { - foreach ($constraints as $constraint) { - $validator = $this->globalContext->getValidatorFactory()->getInstance($constraint); - $validator->initialize($this); - $validator->validate($value, $constraint); - } - } - - /** - * Returns an array of group names. - * - * @param null|string|string[] $groups The groups to resolve. If a single string is - * passed, it is converted to an array. If null - * is passed, an array containing the current - * group of the context is returned. - * - * @return array An array of validation groups. - */ - private function resolveGroups($groups) - { - return $groups ? (array) $groups : (array) $this->group; - } -} diff --git a/src/Symfony/Component/Validator/ExecutionContextInterface.php b/src/Symfony/Component/Validator/ExecutionContextInterface.php deleted file mode 100644 index 2b6cd01e18ef6..0000000000000 --- a/src/Symfony/Component/Validator/ExecutionContextInterface.php +++ /dev/null @@ -1,327 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator; - -/** - * Stores the validator's state during validation. - * - * For example, let's validate the following object graph: - * - *
- * (Person)---($firstName: string)
- *      \
- *   ($address: Address)---($street: string)
- * 
- * - * We validate the Person instance, which becomes the "root" of the - * validation run (see {@link getRoot}). The state of the context after the - * first step will be like this: - * - *
- * (Person)---($firstName: string)
- *    ^ \
- *   ($address: Address)---($street: string)
- * 
- * - * The validator is stopped at the Person node, both the root and the - * value (see {@link getValue}) of the context point to the Person - * instance. The property path is empty at this point (see {@link getPropertyPath}). - * The metadata of the context is the metadata of the Person node - * (see {@link getMetadata}). - * - * After advancing to the property $firstName of the Person - * instance, the state of the context looks like this: - * - *
- * (Person)---($firstName: string)
- *      \              ^
- *   ($address: Address)---($street: string)
- * 
- * - * The validator is stopped at the property $firstName. The root still - * points to the Person instance, because this is where the validation - * started. The property path is now "firstName" and the current value is the - * value of that property. - * - * After advancing to the $address property and then to the - * $street property of the Address instance, the context state - * looks like this: - * - *
- * (Person)---($firstName: string)
- *      \
- *   ($address: Address)---($street: string)
- *                               ^
- * 
- * - * The validator is stopped at the property $street. The root still - * points to the Person instance, but the property path is now - * "address.street" and the validated value is the value of that property. - * - * Apart from the root, the property path and the currently validated value, - * the execution context also knows the metadata of the current node (see - * {@link getMetadata}) which for example returns a {@link Mapping\PropertyMetadata} - * or a {@link Mapping\ClassMetadata} object. he context also contains the - * validation group that is currently being validated (see {@link getGroup}) and - * the violations that happened up until now (see {@link getViolations}). - * - * Apart from reading the execution context, you can also use - * {@link addViolation} or {@link addViolationAt} to add new violations and - * {@link validate} or {@link validateValue} to validate values that the - * validator otherwise would not reach. - * - * @author Bernhard Schussek - * - * @api - * - * @deprecated since version 2.5, to be removed in 3.0. - * Use {@link Context\ExecutionContextInterface} instead. - */ -interface ExecutionContextInterface -{ - /** - * Adds a violation at the current node of the validation graph. - * - * Note: the parameters $invalidValue, $plural and $code are deprecated since version 2.5 and will be removed in 3.0. - * - * @param string $message The error message - * @param array $params The parameters substituted in the error message - * @param mixed $invalidValue The invalid, validated value - * @param int|null $plural The number to use to pluralize of the message - * @param int|null $code The violation code - * - * @api - */ - public function addViolation($message, array $params = array(), $invalidValue = null, $plural = null, $code = null); - - /** - * Adds a violation at the validation graph node with the given property - * path relative to the current property path. - * - * @param string $subPath The relative property path for the violation - * @param string $message The error message - * @param array $parameters The parameters substituted in the error message - * @param mixed $invalidValue The invalid, validated value - * @param int|null $plural The number to use to pluralize of the message - * @param int|null $code The violation code - * - * @api - * - * @deprecated since version 2.5, to be removed in 3.0. - * Use {@link Context\ExecutionContextInterface::buildViolation()} - * instead. - */ - public function addViolationAt($subPath, $message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null); - - /** - * Validates the given value within the scope of the current validation. - * - * The value may be any value recognized by the used metadata factory - * (see {@link MetadataFactoryInterface::getMetadata}), or an array or a - * traversable object of such values. - * - * Usually you validate a value that is not the current node of the - * execution context. For this case, you can pass the {@link $subPath} - * argument which is appended to the current property path when a violation - * is created. For example, take the following object graph: - * - *
-     * (Person)---($address: Address)---($phoneNumber: PhoneNumber)
-     *                     ^
-     * 
- * - * When the execution context stops at the Person instance, the - * property path is "address". When you validate the PhoneNumber - * instance now, pass "phoneNumber" as sub path to correct the property path - * to "address.phoneNumber": - * - *
-     * $context->validate($address->phoneNumber, 'phoneNumber');
-     * 
- * - * Any violations generated during the validation will be added to the - * violation list that you can access with {@link getViolations}. - * - * @param mixed $value The value to validate. - * @param string $subPath The path to append to the context's property path. - * @param null|string|string[] $groups The groups to validate in. If you don't pass any - * groups here, the current group of the context - * will be used. - * @param bool $traverse Whether to traverse the value if it is an array - * or an instance of \Traversable. - * @param bool $deep Whether to traverse the value recursively if - * it is a collection of collections. - * - * @deprecated since version 2.5, to be removed in 3.0. - * Use {@link Context\ExecutionContextInterface::getValidator()} - * instead. - */ - public function validate($value, $subPath = '', $groups = null, $traverse = false, $deep = false); - - /** - * Validates a value against a constraint. - * - * Use the parameter $subPath to adapt the property path for the - * validated value. For example, take the following object graph: - * - *
-     * (Person)---($address: Address)---($street: string)
-     *                     ^
-     * 
- * - * When the validator validates the Address instance, the - * property path stored in the execution context is "address". When you - * manually validate the property $street now, pass the sub path - * "street" to adapt the full property path to "address.street": - * - *
-     * $context->validate($address->street, new NotNull(), 'street');
-     * 
- * - * @param mixed $value The value to validate. - * @param Constraint|Constraint[] $constraints The constraint(s) to validate against. - * @param string $subPath The path to append to the context's property path. - * @param null|string|string[] $groups The groups to validate in. If you don't pass any - * groups here, the current group of the context - * will be used. - * - * @deprecated since version 2.5, to be removed in 3.0. - * Use {@link Context\ExecutionContextInterface::getValidator()} - * instead. - */ - public function validateValue($value, $constraints, $subPath = '', $groups = null); - - /** - * Returns the violations generated by the validator so far. - * - * @return ConstraintViolationListInterface The constraint violation list. - * - * @api - */ - public function getViolations(); - - /** - * Returns the value at which validation was started in the object graph. - * - * The validator, when given an object, traverses the properties and - * related objects and their properties. The root of the validation is the - * object from which the traversal started. - * - * The current value is returned by {@link getValue}. - * - * @return mixed The root value of the validation. - */ - public function getRoot(); - - /** - * Returns the value that the validator is currently validating. - * - * If you want to retrieve the object that was originally passed to the - * validator, use {@link getRoot}. - * - * @return mixed The currently validated value. - */ - public function getValue(); - - /** - * Returns the metadata for the currently validated value. - * - * With the core implementation, this method returns a - * {@link Mapping\ClassMetadata} instance if the current value is an object, - * a {@link Mapping\PropertyMetadata} instance if the current value is - * the value of a property and a {@link Mapping\GetterMetadata} instance if - * the validated value is the result of a getter method. - * - * If the validated value is neither of these, for example if the validator - * has been called with a plain value and constraint, this method returns - * null. - * - * @return MetadataInterface|null The metadata of the currently validated - * value. - */ - public function getMetadata(); - - /** - * Returns the used metadata factory. - * - * @return MetadataFactoryInterface The metadata factory. - * - * @deprecated since version 2.5, to be removed in 3.0. - * Use {@link Context\ExecutionContextInterface::getValidator()} - * instead and call - * {@link Validator\ValidatorInterface::getMetadataFor()} or - * {@link Validator\ValidatorInterface::hasMetadataFor()} there. - */ - public function getMetadataFactory(); - - /** - * Returns the validation group that is currently being validated. - * - * @return string The current validation group. - */ - public function getGroup(); - - /** - * Returns the class name of the current node. - * - * If the metadata of the current node does not implement - * {@link ClassBasedInterface} or if no metadata is available for the - * current node, this method returns null. - * - * @return string|null The class name or null, if no class name could be found. - */ - public function getClassName(); - - /** - * Returns the property name of the current node. - * - * If the metadata of the current node does not implement - * {@link PropertyMetadataInterface} or if no metadata is available for the - * current node, this method returns null. - * - * @return string|null The property name or null, if no property name could be found. - */ - public function getPropertyName(); - - /** - * Returns the property path to the value that the validator is currently - * validating. - * - * For example, take the following object graph: - * - *
-     * (Person)---($address: Address)---($street: string)
-     * 
- * - * When the Person instance is passed to the validator, the - * property path is initially empty. When the $address property - * of that person is validated, the property path is "address". When - * the $street property of the related Address instance - * is validated, the property path is "address.street". - * - * Properties of objects are prefixed with a dot in the property path. - * Indices of arrays or objects implementing the {@link \ArrayAccess} - * interface are enclosed in brackets. For example, if the property in - * the previous example is $addresses and contains an array - * of Address instance, the property path generated for the - * $street property of one of these addresses is for example - * "addresses[0].street". - * - * @param string $subPath Optional. The suffix appended to the current - * property path. - * - * @return string The current property path. The result may be an empty - * string if the validator is currently validating the - * root value of the validation graph. - */ - public function getPropertyPath($subPath = ''); -} diff --git a/src/Symfony/Component/Validator/GlobalExecutionContextInterface.php b/src/Symfony/Component/Validator/GlobalExecutionContextInterface.php deleted file mode 100644 index 5c646f294baee..0000000000000 --- a/src/Symfony/Component/Validator/GlobalExecutionContextInterface.php +++ /dev/null @@ -1,71 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator; - -/** - * Stores the node-independent state of a validation run. - * - * When the validator validates a graph of objects, it uses two classes to - * store the state during the validation: - * - *
    - *
  • For each node in the validation graph (objects, properties, getters) the - * validator creates an instance of {@link ExecutionContextInterface} that - * stores the information about that node.
  • - *
  • One single GlobalExecutionContextInterface stores the state - * that is independent of the current node.
  • - *
- * - * @author Bernhard Schussek - * - * @deprecated since version 2.5, to be removed in 3.0. - * Use {@link Context\ExecutionContextInterface} instead. - */ -interface GlobalExecutionContextInterface -{ - /** - * Returns the violations generated by the validator so far. - * - * @return ConstraintViolationListInterface A list of constraint violations. - */ - public function getViolations(); - - /** - * Returns the value at which validation was started in the object graph. - * - * @return mixed The root value. - * - * @see ExecutionContextInterface::getRoot() - */ - public function getRoot(); - - /** - * Returns the visitor instance used to validate the object graph nodes. - * - * @return ValidationVisitorInterface The validation visitor. - */ - public function getVisitor(); - - /** - * Returns the factory for constraint validators. - * - * @return ConstraintValidatorFactoryInterface The constraint validator factory. - */ - public function getValidatorFactory(); - - /** - * Returns the factory for validation metadata objects. - * - * @return MetadataFactoryInterface The metadata factory. - */ - public function getMetadataFactory(); -} diff --git a/src/Symfony/Component/Validator/Mapping/BlackholeMetadataFactory.php b/src/Symfony/Component/Validator/Mapping/BlackholeMetadataFactory.php deleted file mode 100644 index 01b80138d590e..0000000000000 --- a/src/Symfony/Component/Validator/Mapping/BlackholeMetadataFactory.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator\Mapping; - -@trigger_error('The '.__NAMESPACE__.'\BlackholeMetadataFactory class is deprecated since version 2.5 and will be removed in 3.0. Use the Symfony\Component\Validator\Mapping\Factory\BlackHoleMetadataFactory class instead.', E_USER_DEPRECATED); - -use Symfony\Component\Validator\Mapping\Factory\BlackHoleMetadataFactory as MappingBlackHoleMetadataFactory; - -/** - * Alias of {@link Factory\BlackHoleMetadataFactory}. - * - * @author Fabien Potencier - * - * @deprecated since version 2.5, to be removed in 3.0. - * Use {@link Factory\BlackHoleMetadataFactory} instead. - */ -class BlackholeMetadataFactory extends MappingBlackHoleMetadataFactory -{ -} diff --git a/src/Symfony/Component/Validator/Mapping/Cache/ApcCache.php b/src/Symfony/Component/Validator/Mapping/Cache/ApcCache.php deleted file mode 100644 index 63fc8ac05a405..0000000000000 --- a/src/Symfony/Component/Validator/Mapping/Cache/ApcCache.php +++ /dev/null @@ -1,57 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator\Mapping\Cache; - -@trigger_error('The '.__NAMESPACE__.'\ApcCache class is deprecated since version 2.5 and will be removed in 3.0. Use DoctrineCache with the Doctrine\Common\Cache\ApcCache class instead.', E_USER_DEPRECATED); - -use Symfony\Component\Validator\Mapping\ClassMetadata; - -/** - * @deprecated since version 2.5, to be removed in 3.0. - * Use DoctrineCache with \Doctrine\Common\Cache\ApcCache instead. - */ -class ApcCache implements CacheInterface -{ - private $prefix; - - public function __construct($prefix) - { - if (!extension_loaded('apc')) { - throw new \RuntimeException('Unable to use ApcCache to cache validator mappings as APC is not enabled.'); - } - - $this->prefix = $prefix; - } - - public function has($class) - { - if (!function_exists('apc_exists')) { - $exists = false; - - apc_fetch($this->prefix.$class, $exists); - - return $exists; - } - - return apc_exists($this->prefix.$class); - } - - public function read($class) - { - return apc_fetch($this->prefix.$class); - } - - public function write(ClassMetadata $metadata) - { - apc_store($this->prefix.$metadata->getClassName(), $metadata); - } -} diff --git a/src/Symfony/Component/Validator/Mapping/ClassMetadata.php b/src/Symfony/Component/Validator/Mapping/ClassMetadata.php index 3f4f51b83b41c..d38dd322b3a4b 100644 --- a/src/Symfony/Component/Validator/Mapping/ClassMetadata.php +++ b/src/Symfony/Component/Validator/Mapping/ClassMetadata.php @@ -17,7 +17,6 @@ use Symfony\Component\Validator\Constraints\Valid; use Symfony\Component\Validator\Exception\ConstraintDefinitionException; use Symfony\Component\Validator\Exception\GroupDefinitionException; -use Symfony\Component\Validator\ValidationVisitorInterface; /** * Default implementation of {@link ClassMetadataInterface}. @@ -27,7 +26,7 @@ * @author Bernhard Schussek * @author Fabien Potencier */ -class ClassMetadata extends ElementMetadata implements ClassMetadataInterface +class ClassMetadata extends GenericMetadata implements ClassMetadataInterface { /** * @var string @@ -126,47 +125,6 @@ public function __construct($class) } } - /** - * {@inheritdoc} - * - * @deprecated since version 2.5, to be removed in 3.0. - */ - public function accept(ValidationVisitorInterface $visitor, $value, $group, $propertyPath, $propagatedGroup = null) - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED); - - if (null === $propagatedGroup && Constraint::DEFAULT_GROUP === $group - && ($this->hasGroupSequence() || $this->isGroupSequenceProvider())) { - if ($this->hasGroupSequence()) { - $groups = $this->getGroupSequence()->groups; - } else { - $groups = $value->getGroupSequence(); - } - - foreach ($groups as $group) { - $this->accept($visitor, $value, $group, $propertyPath, Constraint::DEFAULT_GROUP); - - if (count($visitor->getViolations()) > 0) { - break; - } - } - - return; - } - - $visitor->visit($this, $value, $group, $propertyPath); - - if (null !== $value) { - $pathPrefix = empty($propertyPath) ? '' : $propertyPath.'.'; - - foreach ($this->getConstrainedProperties() as $property) { - foreach ($this->getPropertyMetadata($property) as $member) { - $member->accept($visitor, $member->getPropertyValue($value), $group, $pathPrefix.$property, $propagatedGroup); - } - } - } - } - /** * {@inheritdoc} */ @@ -368,52 +326,6 @@ public function mergeConstraints(ClassMetadata $source) } } - /** - * Adds a member metadata. - * - * @param MemberMetadata $metadata - * - * @deprecated since version 2.6, to be removed in 3.0. - */ - protected function addMemberMetadata(MemberMetadata $metadata) - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 2.6 and will be removed in 3.0. Use the addPropertyMetadata() method instead.', E_USER_DEPRECATED); - - $this->addPropertyMetadata($metadata); - } - - /** - * Returns true if metadatas of members is present for the given property. - * - * @param string $property The name of the property - * - * @return bool - * - * @deprecated since version 2.6, to be removed in 3.0. Use {@link hasPropertyMetadata} instead. - */ - public function hasMemberMetadatas($property) - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 2.6 and will be removed in 3.0. Use the hasPropertyMetadata() method instead.', E_USER_DEPRECATED); - - return $this->hasPropertyMetadata($property); - } - - /** - * Returns all metadatas of members describing the given property. - * - * @param string $property The name of the property - * - * @return MemberMetadata[] An array of MemberMetadata - * - * @deprecated since version 2.6, to be removed in 3.0. Use {@link getPropertyMetadata} instead. - */ - public function getMemberMetadatas($property) - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 2.6 and will be removed in 3.0. Use the getPropertyMetadata() method instead.', E_USER_DEPRECATED); - - return $this->getPropertyMetadata($property); - } - /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/Validator/Mapping/ClassMetadataFactory.php b/src/Symfony/Component/Validator/Mapping/ClassMetadataFactory.php deleted file mode 100644 index 4069b3fbcad0e..0000000000000 --- a/src/Symfony/Component/Validator/Mapping/ClassMetadataFactory.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator\Mapping; - -@trigger_error('The '.__NAMESPACE__.'\ClassMetadataFactory class is deprecated since version 2.5 and will be removed in 3.0. Use the Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory class instead.', E_USER_DEPRECATED); - -use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory; - -/** - * Alias of {@link LazyLoadingMetadataFactory}. - * - * @author Bernhard Schussek - * - * @deprecated since version 2.5, to be removed in 3.0. - * Use {@link LazyLoadingMetadataFactory} instead. - */ -class ClassMetadataFactory extends LazyLoadingMetadataFactory -{ -} diff --git a/src/Symfony/Component/Validator/Mapping/ClassMetadataInterface.php b/src/Symfony/Component/Validator/Mapping/ClassMetadataInterface.php index 577440d61d8c7..20cf1bb121f2b 100644 --- a/src/Symfony/Component/Validator/Mapping/ClassMetadataInterface.php +++ b/src/Symfony/Component/Validator/Mapping/ClassMetadataInterface.php @@ -11,9 +11,6 @@ namespace Symfony\Component\Validator\Mapping; -use Symfony\Component\Validator\ClassBasedInterface; -use Symfony\Component\Validator\PropertyMetadataContainerInterface as LegacyPropertyMetadataContainerInterface; - /** * Stores all metadata needed for validating objects of specific class. * @@ -33,7 +30,7 @@ * @see \Symfony\Component\Validator\GroupSequenceProviderInterface * @see TraversalStrategy */ -interface ClassMetadataInterface extends MetadataInterface, LegacyPropertyMetadataContainerInterface, ClassBasedInterface +interface ClassMetadataInterface extends MetadataInterface { /** * Returns the names of all constrained properties. diff --git a/src/Symfony/Component/Validator/Mapping/ElementMetadata.php b/src/Symfony/Component/Validator/Mapping/ElementMetadata.php deleted file mode 100644 index 69fe8bfa73729..0000000000000 --- a/src/Symfony/Component/Validator/Mapping/ElementMetadata.php +++ /dev/null @@ -1,30 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator\Mapping; - -/** - * Contains the metadata of a structural element. - * - * @author Bernhard Schussek - * - * @deprecated since version 2.5, to be removed in 3.0. - * Extend {@link GenericMetadata} instead. - */ -abstract class ElementMetadata extends GenericMetadata -{ - public function __construct() - { - if (!$this instanceof MemberMetadata && !$this instanceof ClassMetadata) { - @trigger_error('The '.__CLASS__.' class is deprecated since version 2.5 and will be removed in 3.0. Use the Symfony\Component\Validator\Mapping\GenericMetadata class instead.', E_USER_DEPRECATED); - } - } -} diff --git a/src/Symfony/Component/Validator/Mapping/Factory/LazyLoadingMetadataFactory.php b/src/Symfony/Component/Validator/Mapping/Factory/LazyLoadingMetadataFactory.php index 6c5c277ed8dc4..288428786e877 100644 --- a/src/Symfony/Component/Validator/Mapping/Factory/LazyLoadingMetadataFactory.php +++ b/src/Symfony/Component/Validator/Mapping/Factory/LazyLoadingMetadataFactory.php @@ -14,8 +14,6 @@ use Symfony\Component\Validator\Exception\NoSuchMetadataException; use Symfony\Component\Validator\Mapping\Cache\CacheInterface; use Symfony\Component\Validator\Mapping\ClassMetadata; -use Symfony\Component\Validator\Mapping\ClassMetadataInterface; -use Symfony\Component\Validator\Mapping\Loader\LoaderChain; use Symfony\Component\Validator\Mapping\Loader\LoaderInterface; /** diff --git a/src/Symfony/Component/Validator/Mapping/Factory/MetadataFactoryInterface.php b/src/Symfony/Component/Validator/Mapping/Factory/MetadataFactoryInterface.php index 6e55e771dd1aa..303d7d2017583 100644 --- a/src/Symfony/Component/Validator/Mapping/Factory/MetadataFactoryInterface.php +++ b/src/Symfony/Component/Validator/Mapping/Factory/MetadataFactoryInterface.php @@ -11,7 +11,7 @@ namespace Symfony\Component\Validator\Mapping\Factory; -use Symfony\Component\Validator\MetadataFactoryInterface as LegacyMetadataFactoryInterface; +use Symfony\Component\Validator\Mapping\ClassMetadataInterface; /** * Returns {@link \Symfony\Component\Validator\Mapping\MetadataInterface} instances for values. @@ -20,6 +20,21 @@ * * @author Bernhard Schussek */ -interface MetadataFactoryInterface extends LegacyMetadataFactoryInterface +interface MetadataFactoryInterface { + /** + * @param string|object $value + * + * @return ClassMetadataInterface + */ + public function getMetadataFor($value); + + /** + * Checks if class has metadata. + * + * @param mixed $value + * + * @return bool + */ + public function hasMetadataFor($value); } diff --git a/src/Symfony/Component/Validator/Mapping/GenericMetadata.php b/src/Symfony/Component/Validator/Mapping/GenericMetadata.php index 3459074fcabf7..caaccbe287abd 100644 --- a/src/Symfony/Component/Validator/Mapping/GenericMetadata.php +++ b/src/Symfony/Component/Validator/Mapping/GenericMetadata.php @@ -14,9 +14,7 @@ use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Constraints\Traverse; use Symfony\Component\Validator\Constraints\Valid; -use Symfony\Component\Validator\Exception\BadMethodCallException; use Symfony\Component\Validator\Exception\ConstraintDefinitionException; -use Symfony\Component\Validator\ValidationVisitorInterface; /** * A generic container of {@link Constraint} objects. @@ -225,21 +223,4 @@ public function getTraversalStrategy() { return $this->traversalStrategy; } - - /** - * Exists for compatibility with the deprecated - * {@link Symfony\Component\Validator\MetadataInterface}. - * - * Should not be used. - * - * Implemented for backward compatibility with Symfony < 2.5. - * - * @throws BadMethodCallException - * - * @deprecated since version 2.5, to be removed in 3.0. - */ - public function accept(ValidationVisitorInterface $visitor, $value, $group, $propertyPath) - { - throw new BadMethodCallException('Not supported.'); - } } diff --git a/src/Symfony/Component/Validator/Mapping/MemberMetadata.php b/src/Symfony/Component/Validator/Mapping/MemberMetadata.php index 0def248431f2d..edeed3749ee94 100644 --- a/src/Symfony/Component/Validator/Mapping/MemberMetadata.php +++ b/src/Symfony/Component/Validator/Mapping/MemberMetadata.php @@ -13,7 +13,6 @@ use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Exception\ConstraintDefinitionException; -use Symfony\Component\Validator\ValidationVisitorInterface; /** * Stores all metadata needed for validating a class property. @@ -27,7 +26,7 @@ * * @see PropertyMetadataInterface */ -abstract class MemberMetadata extends ElementMetadata implements PropertyMetadataInterface +abstract class MemberMetadata extends GenericMetadata implements PropertyMetadataInterface { /** * @var string @@ -75,22 +74,6 @@ public function __construct($class, $name, $property) $this->property = $property; } - /** - * {@inheritdoc} - * - * @deprecated since version 2.5, to be removed in 3.0. - */ - public function accept(ValidationVisitorInterface $visitor, $value, $group, $propertyPath, $propagatedGroup = null) - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED); - - $visitor->visit($this, $value, $group, $propertyPath); - - if ($this->isCascaded()) { - $visitor->validate($value, $propagatedGroup ?: $group, $propertyPath, $this->isCollectionCascaded(), $this->isCollectionCascadedDeeply()); - } - } - /** * {@inheritdoc} */ @@ -182,53 +165,6 @@ public function isPrivate($objectOrClassName) return $this->getReflectionMember($objectOrClassName)->isPrivate(); } - /** - * Returns whether objects stored in this member should be validated. - * - * @return bool - * - * @deprecated since version 2.5, to be removed in 3.0. - * Use {@link getCascadingStrategy()} instead. - */ - public function isCascaded() - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0. Use the getCascadingStrategy() method instead.', E_USER_DEPRECATED); - - return (bool) ($this->cascadingStrategy & CascadingStrategy::CASCADE); - } - - /** - * Returns whether arrays or traversable objects stored in this member - * should be traversed and validated in each entry. - * - * @return bool - * - * @deprecated since version 2.5, to be removed in 3.0. - * Use {@link getTraversalStrategy()} instead. - */ - public function isCollectionCascaded() - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0. Use the getTraversalStrategy() method instead.', E_USER_DEPRECATED); - - return (bool) ($this->traversalStrategy & (TraversalStrategy::IMPLICIT | TraversalStrategy::TRAVERSE)); - } - - /** - * Returns whether arrays or traversable objects stored in this member - * should be traversed recursively for inner arrays/traversable objects. - * - * @return bool - * - * @deprecated since version 2.5, to be removed in 3.0. - * Use {@link getTraversalStrategy()} instead. - */ - public function isCollectionCascadedDeeply() - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0. Use the getTraversalStrategy() method instead.', E_USER_DEPRECATED); - - return !($this->traversalStrategy & TraversalStrategy::STOP_RECURSION); - } - /** * Returns the reflection instance for accessing the member's value. * diff --git a/src/Symfony/Component/Validator/Mapping/MetadataInterface.php b/src/Symfony/Component/Validator/Mapping/MetadataInterface.php index e5f09e17edc82..894c3831a6f32 100644 --- a/src/Symfony/Component/Validator/Mapping/MetadataInterface.php +++ b/src/Symfony/Component/Validator/Mapping/MetadataInterface.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Validator\Mapping; use Symfony\Component\Validator\Constraint; -use Symfony\Component\Validator\MetadataInterface as LegacyMetadataInterface; /** * A container for validation metadata. @@ -31,7 +30,7 @@ * @see CascadingStrategy * @see TraversalStrategy */ -interface MetadataInterface extends LegacyMetadataInterface +interface MetadataInterface { /** * Returns the strategy for cascading objects. diff --git a/src/Symfony/Component/Validator/Mapping/PropertyMetadataInterface.php b/src/Symfony/Component/Validator/Mapping/PropertyMetadataInterface.php index 8a77aa83faba5..868d1ed39e239 100644 --- a/src/Symfony/Component/Validator/Mapping/PropertyMetadataInterface.php +++ b/src/Symfony/Component/Validator/Mapping/PropertyMetadataInterface.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Validator\Mapping; use Symfony\Component\Validator\ClassBasedInterface; -use Symfony\Component\Validator\PropertyMetadataInterface as LegacyPropertyMetadataInterface; /** * Stores all metadata needed for validating the value of a class property. @@ -32,6 +31,6 @@ * @see CascadingStrategy * @see TraversalStrategy */ -interface PropertyMetadataInterface extends MetadataInterface, LegacyPropertyMetadataInterface, ClassBasedInterface +interface PropertyMetadataInterface extends MetadataInterface, ClassBasedInterface { } diff --git a/src/Symfony/Component/Validator/MetadataFactoryInterface.php b/src/Symfony/Component/Validator/MetadataFactoryInterface.php deleted file mode 100644 index 555bea9aa21e5..0000000000000 --- a/src/Symfony/Component/Validator/MetadataFactoryInterface.php +++ /dev/null @@ -1,43 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator; - -/** - * Returns {@link MetadataInterface} instances for values. - * - * @author Bernhard Schussek - * - * @deprecated since version 2.5, to be removed in 3.0. - * Use {@link Mapping\Factory\MetadataFactoryInterface} instead. - */ -interface MetadataFactoryInterface -{ - /** - * Returns the metadata for the given value. - * - * @param mixed $value Some value - * - * @return MetadataInterface The metadata for the value - * - * @throws Exception\NoSuchMetadataException If no metadata exists for the given value - */ - public function getMetadataFor($value); - - /** - * Returns whether the class is able to return metadata for the given value. - * - * @param mixed $value Some value - * - * @return bool Whether metadata can be returned for that value - */ - public function hasMetadataFor($value); -} diff --git a/src/Symfony/Component/Validator/MetadataInterface.php b/src/Symfony/Component/Validator/MetadataInterface.php deleted file mode 100644 index 2c8944903c6bf..0000000000000 --- a/src/Symfony/Component/Validator/MetadataInterface.php +++ /dev/null @@ -1,73 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator; - -/** - * A container for validation metadata. - * - * The container contains constraints that may belong to different validation - * groups. Constraints for a specific group can be fetched by calling - * {@link findConstraints}. - * - * Implement this interface to add validation metadata to your own metadata - * layer. Each metadata may have named properties. Each property can be - * represented by one or more {@link PropertyMetadataInterface} instances that - * are returned by {@link getPropertyMetadata}. Since - * PropertyMetadataInterface inherits from MetadataInterface, - * each property may be divided into further properties. - * - * The {@link accept} method of each metadata implements the Visitor pattern. - * The method should forward the call to the visitor's - * {@link ValidationVisitorInterface::visit} method and additionally call - * accept() on all structurally related metadata instances. - * - * For example, to store constraints for PHP classes and their properties, - * create a class ClassMetadata (implementing MetadataInterface) - * and a class PropertyMetadata (implementing PropertyMetadataInterface). - * ClassMetadata::getPropertyMetadata($property) returns all - * PropertyMetadata instances for a property of that class. Its - * accept()-method simply forwards to ValidationVisitorInterface::visit() - * and calls accept() on all contained PropertyMetadata - * instances, which themselves call ValidationVisitorInterface::visit() - * again. - * - * @author Bernhard Schussek - * - * @deprecated since version 2.5, to be removed in 3.0. - * Use {@link Mapping\MetadataInterface} instead. - */ -interface MetadataInterface -{ - /** - * Implementation of the Visitor design pattern. - * - * Calls {@link ValidationVisitorInterface::visit} and then forwards the - * accept()-call to all property metadata instances. - * - * @param ValidationVisitorInterface $visitor The visitor implementing the validation logic - * @param mixed $value The value to validate - * @param string|string[] $group The validation group to validate in - * @param string $propertyPath The current property path in the validation graph - * - * @deprecated since version 2.5, to be removed in 3.0. - */ - public function accept(ValidationVisitorInterface $visitor, $value, $group, $propertyPath); - - /** - * Returns all constraints for a given validation group. - * - * @param string $group The validation group - * - * @return Constraint[] A list of constraint instances - */ - public function findConstraints($group); -} diff --git a/src/Symfony/Component/Validator/PropertyMetadataContainerInterface.php b/src/Symfony/Component/Validator/PropertyMetadataContainerInterface.php deleted file mode 100644 index 5441be1c3d063..0000000000000 --- a/src/Symfony/Component/Validator/PropertyMetadataContainerInterface.php +++ /dev/null @@ -1,45 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator; - -/** - * A container for {@link PropertyMetadataInterface} instances. - * - * @author Bernhard Schussek - * - * @deprecated since version 2.5, to be removed in 3.0. - * Use {@link Mapping\ClassMetadataInterface} instead. - */ -interface PropertyMetadataContainerInterface -{ - /** - * Check if there's any metadata attached to the given named property. - * - * @param string $property The property name. - * - * @return bool - */ - public function hasPropertyMetadata($property); - - /** - * Returns all metadata instances for the given named property. - * - * If your implementation does not support properties, simply throw an - * exception in this method (for example a BadMethodCallException). - * - * @param string $property The property name. - * - * @return PropertyMetadataInterface[] A list of metadata instances. Empty if - * no metadata exists for the property. - */ - public function getPropertyMetadata($property); -} diff --git a/src/Symfony/Component/Validator/PropertyMetadataInterface.php b/src/Symfony/Component/Validator/PropertyMetadataInterface.php deleted file mode 100644 index 46e7c692c85ca..0000000000000 --- a/src/Symfony/Component/Validator/PropertyMetadataInterface.php +++ /dev/null @@ -1,46 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator; - -/** - * A container for validation metadata of a property. - * - * What exactly you define as "property" is up to you. The validator expects - * implementations of {@link MetadataInterface} that contain constraints and - * optionally a list of named properties that also have constraints (and may - * have further sub properties). Such properties are mapped by implementations - * of this interface. - * - * @author Bernhard Schussek - * - * @see MetadataInterface - * @deprecated since version 2.5, to be removed in 3.0. - * Use {@link Mapping\PropertyMetadataInterface} instead. - */ -interface PropertyMetadataInterface extends MetadataInterface -{ - /** - * Returns the name of the property. - * - * @return string The property name. - */ - public function getPropertyName(); - - /** - * Extracts the value of the property from the given container. - * - * @param mixed $containingValue The container to extract the property value from. - * - * @return mixed The value of the property. - */ - public function getPropertyValue($containingValue); -} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/AbstractConstraintValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/AbstractConstraintValidatorTest.php index 5a5fa51a0af48..2e11bd92d5aa8 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/AbstractConstraintValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/AbstractConstraintValidatorTest.php @@ -17,8 +17,6 @@ use Symfony\Component\Validator\ConstraintViolation; use Symfony\Component\Validator\Context\ExecutionContext; use Symfony\Component\Validator\Context\ExecutionContextInterface; -use Symfony\Component\Validator\Context\LegacyExecutionContext; -use Symfony\Component\Validator\ExecutionContextInterface as LegacyExecutionContextInterface; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\PropertyMetadata; use Symfony\Component\Validator\Validation; @@ -100,26 +98,11 @@ protected function createContext() $validator = $this->getMock('Symfony\Component\Validator\Validator\ValidatorInterface'); $contextualValidator = $this->getMock('Symfony\Component\Validator\Validator\ContextualValidatorInterface'); - switch ($this->getApiVersion()) { - case Validation::API_VERSION_2_5: - $context = new ExecutionContext( - $validator, - $this->root, - $translator - ); - break; - case Validation::API_VERSION_2_4: - case Validation::API_VERSION_2_5_BC: - $context = new LegacyExecutionContext( - $validator, - $this->root, - $this->getMock('Symfony\Component\Validator\MetadataFactoryInterface'), - $translator - ); - break; - default: - throw new \RuntimeException('Invalid API version'); - } + $context = new ExecutionContext( + $validator, + $this->root, + $translator + ); $context->setGroup($this->group); $context->setNode($this->value, $this->object, $this->metadata, $this->propertyPath); @@ -133,33 +116,6 @@ protected function createContext() return $context; } - /** - * @param mixed $message - * @param array $parameters - * @param string $propertyPath - * @param string $invalidValue - * @param null $plural - * @param null $code - * - * @return ConstraintViolation - * - * @deprecated to be removed in Symfony 3.0. Use {@link buildViolation()} instead. - */ - protected function createViolation($message, array $parameters = array(), $propertyPath = 'property.path', $invalidValue = 'InvalidValue', $plural = null, $code = null) - { - return new ConstraintViolation( - null, - $message, - $parameters, - $this->root, - $propertyPath, - $invalidValue, - $plural, - $code, - $this->constraint - ); - } - protected function setGroup($group) { $this->group = $group; @@ -243,51 +199,6 @@ protected function assertNoViolation() $this->assertSame(0, $violationsCount = count($this->context->getViolations()), sprintf('0 violation expected. Got %u.', $violationsCount)); } - /** - * @param mixed $message - * @param array $parameters - * @param string $propertyPath - * @param string $invalidValue - * @param null $plural - * @param null $code - * - * @deprecated To be removed in Symfony 3.0. Use - * {@link buildViolation()} instead. - */ - protected function assertViolation($message, array $parameters = array(), $propertyPath = 'property.path', $invalidValue = 'InvalidValue', $plural = null, $code = null) - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 2.3 and will be removed in 3.0. Use the buildViolation() method instead.', E_USER_DEPRECATED); - - $this->buildViolation($message) - ->setParameters($parameters) - ->atPath($propertyPath) - ->setInvalidValue($invalidValue) - ->setCode($code) - ->setPlural($plural) - ->assertRaised(); - } - - /** - * @param array $expected - * - * @deprecated To be removed in Symfony 3.0. Use - * {@link buildViolation()} instead. - */ - protected function assertViolations(array $expected) - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 2.3 and will be removed in 3.0. Use the buildViolation() method instead.', E_USER_DEPRECATED); - - $violations = $this->context->getViolations(); - - $this->assertCount(count($expected), $violations); - - $i = 0; - - foreach ($expected as $violation) { - $this->assertEquals($violation, $violations[$i++]); - } - } - /** * @param $message * @@ -312,7 +223,7 @@ abstract protected function createValidator(); class ConstraintViolationAssertion { /** - * @var LegacyExecutionContextInterface + * @var ExecutionContextInterface */ private $context; @@ -331,7 +242,7 @@ class ConstraintViolationAssertion private $constraint; private $cause; - public function __construct(LegacyExecutionContextInterface $context, $message, Constraint $constraint = null, array $assertions = array()) + public function __construct(ExecutionContextInterface $context, $message, Constraint $constraint = null, array $assertions = array()) { $this->context = $context; $this->message = $message; diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php index 385c19ab241a2..2d33e188cc756 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php @@ -14,7 +14,7 @@ use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Constraints\Callback; use Symfony\Component\Validator\Constraints\CallbackValidator; -use Symfony\Component\Validator\ExecutionContextInterface; +use Symfony\Component\Validator\Context\ExecutionContextInterface; use Symfony\Component\Validator\Validation; class CallbackValidatorTest_Class diff --git a/src/Symfony/Component/Validator/Tests/Fixtures/FakeMetadataFactory.php b/src/Symfony/Component/Validator/Tests/Fixtures/FakeMetadataFactory.php index e3f0d9a007800..dc748fb580878 100644 --- a/src/Symfony/Component/Validator/Tests/Fixtures/FakeMetadataFactory.php +++ b/src/Symfony/Component/Validator/Tests/Fixtures/FakeMetadataFactory.php @@ -12,8 +12,8 @@ namespace Symfony\Component\Validator\Tests\Fixtures; use Symfony\Component\Validator\Exception\NoSuchMetadataException; -use Symfony\Component\Validator\MetadataFactoryInterface; -use Symfony\Component\Validator\MetadataInterface; +use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface; +use Symfony\Component\Validator\Mapping\MetadataInterface; class FakeMetadataFactory implements MetadataFactoryInterface { diff --git a/src/Symfony/Component/Validator/Tests/Fixtures/LegacyClassMetadata.php b/src/Symfony/Component/Validator/Tests/Fixtures/LegacyClassMetadata.php deleted file mode 100644 index 6a832a109f99e..0000000000000 --- a/src/Symfony/Component/Validator/Tests/Fixtures/LegacyClassMetadata.php +++ /dev/null @@ -1,20 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator\Tests\Fixtures; - -use Symfony\Component\Validator\ClassBasedInterface; -use Symfony\Component\Validator\MetadataInterface; -use Symfony\Component\Validator\PropertyMetadataContainerInterface; - -interface LegacyClassMetadata extends MetadataInterface, PropertyMetadataContainerInterface, ClassBasedInterface -{ -} diff --git a/src/Symfony/Component/Validator/Tests/Fixtures/StubGlobalExecutionContext.php b/src/Symfony/Component/Validator/Tests/Fixtures/StubGlobalExecutionContext.php deleted file mode 100644 index 84c5a80bf2d16..0000000000000 --- a/src/Symfony/Component/Validator/Tests/Fixtures/StubGlobalExecutionContext.php +++ /dev/null @@ -1,70 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator\Tests\Fixtures; - -use Symfony\Component\Validator\ConstraintViolationList; -use Symfony\Component\Validator\GlobalExecutionContextInterface; -use Symfony\Component\Validator\ValidationVisitorInterface; - -/** - * @since 2.5.3 - * - * @author Bernhard Schussek - * - * @deprecated since version 2.5, to be removed in 3.0 - */ -class StubGlobalExecutionContext implements GlobalExecutionContextInterface -{ - private $violations; - private $root; - private $visitor; - - public function __construct($root = null, ValidationVisitorInterface $visitor = null) - { - $this->violations = new ConstraintViolationList(); - $this->root = $root; - $this->visitor = $visitor; - } - - public function getViolations() - { - return $this->violations; - } - - public function setRoot($root) - { - $this->root = $root; - } - - public function getRoot() - { - return $this->root; - } - - public function setVisitor(ValidationVisitorInterface $visitor) - { - $this->visitor = $visitor; - } - - public function getVisitor() - { - return $this->visitor; - } - - public function getValidatorFactory() - { - } - - public function getMetadataFactory() - { - } -} diff --git a/src/Symfony/Component/Validator/Tests/Validator/Abstract2Dot5ApiTest.php b/src/Symfony/Component/Validator/Tests/Validator/Abstract2Dot5ApiTest.php index 099fe3b5a5d55..083cb9f3b4ca3 100644 --- a/src/Symfony/Component/Validator/Tests/Validator/Abstract2Dot5ApiTest.php +++ b/src/Symfony/Component/Validator/Tests/Validator/Abstract2Dot5ApiTest.php @@ -19,10 +19,9 @@ use Symfony\Component\Validator\ConstraintViolationInterface; use Symfony\Component\Validator\Context\ExecutionContextInterface; use Symfony\Component\Validator\Mapping\ClassMetadata; -use Symfony\Component\Validator\MetadataFactoryInterface; +use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface; use Symfony\Component\Validator\Tests\Fixtures\Entity; use Symfony\Component\Validator\Tests\Fixtures\FailingConstraint; -use Symfony\Component\Validator\Tests\Fixtures\FakeClassMetadata; use Symfony\Component\Validator\Tests\Fixtures\Reference; use Symfony\Component\Validator\Validator\ValidatorInterface; diff --git a/src/Symfony/Component/Validator/Tests/Validator/AbstractValidatorTest.php b/src/Symfony/Component/Validator/Tests/Validator/AbstractValidatorTest.php index f3a2a64338822..2b3b1e5bc3005 100644 --- a/src/Symfony/Component/Validator/Tests/Validator/AbstractValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Validator/AbstractValidatorTest.php @@ -15,7 +15,7 @@ use Symfony\Component\Validator\Constraints\GroupSequence; use Symfony\Component\Validator\Constraints\Valid; use Symfony\Component\Validator\ConstraintViolationInterface; -use Symfony\Component\Validator\ExecutionContextInterface; +use Symfony\Component\Validator\Context\ExecutionContextInterface; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Tests\Fixtures\Entity; use Symfony\Component\Validator\Tests\Fixtures\FakeMetadataFactory; diff --git a/src/Symfony/Component/Validator/Tests/Validator/RecursiveValidator2Dot5ApiTest.php b/src/Symfony/Component/Validator/Tests/Validator/RecursiveValidator2Dot5ApiTest.php index b27e6454bea7a..7387a821a5eb8 100644 --- a/src/Symfony/Component/Validator/Tests/Validator/RecursiveValidator2Dot5ApiTest.php +++ b/src/Symfony/Component/Validator/Tests/Validator/RecursiveValidator2Dot5ApiTest.php @@ -14,7 +14,7 @@ use Symfony\Component\Translation\IdentityTranslator; use Symfony\Component\Validator\ConstraintValidatorFactory; use Symfony\Component\Validator\Context\ExecutionContextFactory; -use Symfony\Component\Validator\MetadataFactoryInterface; +use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface; use Symfony\Component\Validator\Tests\Fixtures\Entity; use Symfony\Component\Validator\Validator\RecursiveValidator; diff --git a/src/Symfony/Component/Validator/Validation.php b/src/Symfony/Component/Validator/Validation.php index 1693f7311add4..de77e838fb6ff 100644 --- a/src/Symfony/Component/Validator/Validation.php +++ b/src/Symfony/Component/Validator/Validation.php @@ -18,24 +18,6 @@ */ final class Validation { - /** - * The Validator API provided by Symfony 2.4 and older. - * - * @deprecated use API_VERSION_2_5_BC instead. - */ - const API_VERSION_2_4 = 1; - - /** - * The Validator API provided by Symfony 2.5 and newer. - */ - const API_VERSION_2_5 = 2; - - /** - * The Validator API provided by Symfony 2.5 and newer with a backwards - * compatibility layer for 2.4 and older. - */ - const API_VERSION_2_5_BC = 3; - /** * Creates a new validator. * diff --git a/src/Symfony/Component/Validator/ValidationVisitor.php b/src/Symfony/Component/Validator/ValidationVisitor.php deleted file mode 100644 index 838646260f36b..0000000000000 --- a/src/Symfony/Component/Validator/ValidationVisitor.php +++ /dev/null @@ -1,212 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator; - -@trigger_error('The '.__NAMESPACE__.'\ValidationVisitor class is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED); - -use Symfony\Component\Translation\TranslatorInterface; -use Symfony\Component\Validator\Exception\NoSuchMetadataException; -use Symfony\Component\Validator\Exception\UnexpectedTypeException; - -/** - * Default implementation of {@link ValidationVisitorInterface} and - * {@link GlobalExecutionContextInterface}. - * - * @author Bernhard Schussek - * - * @deprecated since version 2.5, to be removed in 3.0. - */ -class ValidationVisitor implements ValidationVisitorInterface, GlobalExecutionContextInterface -{ - /** - * @var mixed - */ - private $root; - - /** - * @var MetadataFactoryInterface - */ - private $metadataFactory; - - /** - * @var ConstraintValidatorFactoryInterface - */ - private $validatorFactory; - - /** - * @var TranslatorInterface - */ - private $translator; - - /** - * @var null|string - */ - private $translationDomain; - - /** - * @var array - */ - private $objectInitializers; - - /** - * @var ConstraintViolationList - */ - private $violations; - - /** - * @var array - */ - private $validatedObjects = array(); - - /** - * Creates a new validation visitor. - * - * @param mixed $root The value passed to the validator. - * @param MetadataFactoryInterface $metadataFactory The factory for obtaining metadata instances. - * @param ConstraintValidatorFactoryInterface $validatorFactory The factory for creating constraint validators. - * @param TranslatorInterface $translator The translator for translating violation messages. - * @param string|null $translationDomain The domain of the translation messages. - * @param ObjectInitializerInterface[] $objectInitializers The initializers for preparing objects before validation. - * - * @throws UnexpectedTypeException If any of the object initializers is not an instance of ObjectInitializerInterface - */ - public function __construct($root, MetadataFactoryInterface $metadataFactory, ConstraintValidatorFactoryInterface $validatorFactory, TranslatorInterface $translator, $translationDomain = null, array $objectInitializers = array()) - { - foreach ($objectInitializers as $initializer) { - if (!$initializer instanceof ObjectInitializerInterface) { - throw new UnexpectedTypeException($initializer, 'Symfony\Component\Validator\ObjectInitializerInterface'); - } - } - - $this->root = $root; - $this->metadataFactory = $metadataFactory; - $this->validatorFactory = $validatorFactory; - $this->translator = $translator; - $this->translationDomain = $translationDomain; - $this->objectInitializers = $objectInitializers; - $this->violations = new ConstraintViolationList(); - } - - /** - * {@inheritdoc} - */ - public function visit(MetadataInterface $metadata, $value, $group, $propertyPath) - { - $context = new ExecutionContext( - $this, - $this->translator, - $this->translationDomain, - $metadata, - $value, - $group, - $propertyPath - ); - - $context->validateValue($value, $metadata->findConstraints($group)); - } - - /** - * {@inheritdoc} - */ - public function validate($value, $group, $propertyPath, $traverse = false, $deep = false) - { - if (null === $value) { - return; - } - - if (is_object($value)) { - $hash = spl_object_hash($value); - - // Exit, if the object is already validated for the current group - if (isset($this->validatedObjects[$hash][$group])) { - return; - } - - // Initialize if the object wasn't initialized before - if (!isset($this->validatedObjects[$hash])) { - foreach ($this->objectInitializers as $initializer) { - if (!$initializer instanceof ObjectInitializerInterface) { - throw new \LogicException('Validator initializers must implement ObjectInitializerInterface.'); - } - $initializer->initialize($value); - } - } - - // Remember validating this object before starting and possibly - // traversing the object graph - $this->validatedObjects[$hash][$group] = true; - } - - // Validate arrays recursively by default, otherwise every driver needs - // to implement special handling for arrays. - // https://github.com/symfony/symfony/issues/6246 - if (is_array($value) || ($traverse && $value instanceof \Traversable)) { - foreach ($value as $key => $element) { - // Ignore any scalar values in the collection - if (is_object($element) || is_array($element)) { - // Only repeat the traversal if $deep is set - $this->validate($element, $group, $propertyPath.'['.$key.']', $deep, $deep); - } - } - - try { - $this->metadataFactory->getMetadataFor($value)->accept($this, $value, $group, $propertyPath); - } catch (NoSuchMetadataException $e) { - // Metadata doesn't necessarily have to exist for - // traversable objects, because we know how to validate - // them anyway. Optionally, additional metadata is supported. - } - } else { - $this->metadataFactory->getMetadataFor($value)->accept($this, $value, $group, $propertyPath); - } - } - - /** - * {@inheritdoc} - */ - public function getViolations() - { - return $this->violations; - } - - /** - * {@inheritdoc} - */ - public function getRoot() - { - return $this->root; - } - - /** - * {@inheritdoc} - */ - public function getVisitor() - { - return $this; - } - - /** - * {@inheritdoc} - */ - public function getValidatorFactory() - { - return $this->validatorFactory; - } - - /** - * {@inheritdoc} - */ - public function getMetadataFactory() - { - return $this->metadataFactory; - } -} diff --git a/src/Symfony/Component/Validator/ValidationVisitorInterface.php b/src/Symfony/Component/Validator/ValidationVisitorInterface.php deleted file mode 100644 index 0ab7b7366776c..0000000000000 --- a/src/Symfony/Component/Validator/ValidationVisitorInterface.php +++ /dev/null @@ -1,82 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator; - -/** - * Validates values against constraints defined in {@link MetadataInterface} - * instances. - * - * This interface is an implementation of the Visitor design pattern. A value - * is validated by first passing it to the {@link validate} method. That method - * will determine the matching {@link MetadataInterface} for validating the - * value. It then calls the {@link MetadataInterface::accept} method of that - * metadata. accept() does two things: - * - *
    - *
  1. It calls {@link visit} to validate the value against the constraints of - * the metadata.
  2. - *
  3. It calls accept() on all nested metadata instances with the - * corresponding values extracted from the current value. For example, if the - * current metadata represents a class and the current value is an object of - * that class, the metadata contains nested instances for each property of that - * class. It forwards the call to these nested metadata with the values of the - * corresponding properties in the original object.
  4. - *
- * - * @author Bernhard Schussek - * - * @deprecated since version 2.5, to be removed in 3.0. - */ -interface ValidationVisitorInterface -{ - /** - * Validates a value. - * - * If the value is an array or a traversable object, you can set the - * parameter $traverse to true in order to run through - * the collection and validate each element. If these elements can be - * collections again and you want to traverse them recursively, set the - * parameter $deep to true as well. - * - * If you set $traversable to true, the visitor will - * nevertheless try to find metadata for the collection and validate its - * constraints. If no such metadata is found, the visitor ignores that and - * only iterates the collection. - * - * If you don't set $traversable to true and the visitor - * does not find metadata for the given value, it will fail with an - * exception. - * - * @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. - * @param bool $traverse Whether to traverse the value if it is traversable. - * @param bool $deep Whether to traverse nested traversable values recursively. - * - * @throws Exception\NoSuchMetadataException If no metadata can be found for - * the given value. - */ - public function validate($value, $group, $propertyPath, $traverse = false, $deep = false); - - /** - * Validates a value against the constraints defined in some metadata. - * - * This method implements the Visitor design pattern. See also - * {@link ValidationVisitorInterface}. - * - * @param MetadataInterface $metadata The metadata holding the constraints. - * @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. - */ - public function visit(MetadataInterface $metadata, $value, $group, $propertyPath); -} diff --git a/src/Symfony/Component/Validator/Validator.php b/src/Symfony/Component/Validator/Validator.php deleted file mode 100644 index 4da27e7b375a0..0000000000000 --- a/src/Symfony/Component/Validator/Validator.php +++ /dev/null @@ -1,237 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator; - -@trigger_error('The '.__NAMESPACE__.'\Validator class is deprecated since version 2.5 and will be removed in 3.0. Use the Symfony\Component\Validator\Validator\RecursiveValidator class instead.', E_USER_DEPRECATED); - -use Symfony\Component\Translation\TranslatorInterface; -use Symfony\Component\Validator\Constraints\Valid; -use Symfony\Component\Validator\Exception\ValidatorException; - -/** - * Default implementation of {@link ValidatorInterface}. - * - * @author Fabien Potencier - * @author Bernhard Schussek - * - * @deprecated since version 2.5, to be removed in 3.0. - * Use {@link Validator\RecursiveValidator} instead. - */ -class Validator implements ValidatorInterface, Mapping\Factory\MetadataFactoryInterface -{ - /** - * @var MetadataFactoryInterface - */ - private $metadataFactory; - - /** - * @var ConstraintValidatorFactoryInterface - */ - private $validatorFactory; - - /** - * @var TranslatorInterface - */ - private $translator; - - /** - * @var null|string - */ - private $translationDomain; - - /** - * @var array - */ - private $objectInitializers; - - public function __construct( - MetadataFactoryInterface $metadataFactory, - ConstraintValidatorFactoryInterface $validatorFactory, - TranslatorInterface $translator, - $translationDomain = 'validators', - array $objectInitializers = array() - ) { - $this->metadataFactory = $metadataFactory; - $this->validatorFactory = $validatorFactory; - $this->translator = $translator; - $this->translationDomain = $translationDomain; - $this->objectInitializers = $objectInitializers; - } - - /** - * {@inheritdoc} - */ - public function getMetadataFactory() - { - return $this->metadataFactory; - } - - /** - * {@inheritdoc} - */ - public function getMetadataFor($value) - { - return $this->metadataFactory->getMetadataFor($value); - } - - /** - * {@inheritdoc} - */ - public function hasMetadataFor($value) - { - return $this->metadataFactory->hasMetadataFor($value); - } - - /** - * {@inheritdoc} - */ - public function validate($value, $groups = null, $traverse = false, $deep = false) - { - $visitor = $this->createVisitor($value); - - foreach ($this->resolveGroups($groups) as $group) { - $visitor->validate($value, $group, '', $traverse, $deep); - } - - return $visitor->getViolations(); - } - - /** - * {@inheritdoc} - * - * @throws ValidatorException If the metadata for the value does not support properties. - */ - public function validateProperty($containingValue, $property, $groups = null) - { - $visitor = $this->createVisitor($containingValue); - $metadata = $this->metadataFactory->getMetadataFor($containingValue); - - if (!$metadata instanceof PropertyMetadataContainerInterface) { - $valueAsString = is_scalar($containingValue) - ? '"'.$containingValue.'"' - : 'the value of type '.gettype($containingValue); - - throw new ValidatorException(sprintf('The metadata for %s does not support properties.', $valueAsString)); - } - - foreach ($this->resolveGroups($groups) as $group) { - if (!$metadata->hasPropertyMetadata($property)) { - continue; - } - - foreach ($metadata->getPropertyMetadata($property) as $propMeta) { - $propMeta->accept($visitor, $propMeta->getPropertyValue($containingValue), $group, $property); - } - } - - return $visitor->getViolations(); - } - - /** - * {@inheritdoc} - * - * @throws ValidatorException If the metadata for the value does not support properties. - */ - public function validatePropertyValue($containingValue, $property, $value, $groups = null) - { - $visitor = $this->createVisitor(is_object($containingValue) ? $containingValue : $value); - $metadata = $this->metadataFactory->getMetadataFor($containingValue); - - if (!$metadata instanceof PropertyMetadataContainerInterface) { - $valueAsString = is_scalar($containingValue) - ? '"'.$containingValue.'"' - : 'the value of type '.gettype($containingValue); - - throw new ValidatorException(sprintf('The metadata for '.$valueAsString.' does not support properties.')); - } - - // If $containingValue is passed as class name, take $value as root - // and start the traversal with an empty property path - $propertyPath = is_object($containingValue) ? $property : ''; - - foreach ($this->resolveGroups($groups) as $group) { - if (!$metadata->hasPropertyMetadata($property)) { - continue; - } - - foreach ($metadata->getPropertyMetadata($property) as $propMeta) { - $propMeta->accept($visitor, $value, $group, $propertyPath); - } - } - - return $visitor->getViolations(); - } - - /** - * {@inheritdoc} - */ - public function validateValue($value, $constraints, $groups = null) - { - $context = new ExecutionContext($this->createVisitor($value), $this->translator, $this->translationDomain); - - $constraints = is_array($constraints) ? $constraints : array($constraints); - - foreach ($constraints as $constraint) { - if ($constraint instanceof Valid) { - // Why can't the Valid constraint be executed directly? - // - // It cannot be executed like regular other constraints, because regular - // constraints are only executed *if they belong to the validated group*. - // The Valid constraint, on the other hand, is always executed and propagates - // the group to the cascaded object. The propagated group depends on - // - // * Whether a group sequence is currently being executed. Then the default - // group is propagated. - // - // * Otherwise the validated group is propagated. - - throw new ValidatorException( - sprintf( - 'The constraint %s cannot be validated. Use the method validate() instead.', - get_class($constraint) - ) - ); - } - - $context->validateValue($value, $constraint, '', $groups); - } - - return $context->getViolations(); - } - - /** - * @param mixed $root - * - * @return ValidationVisitor - */ - private function createVisitor($root) - { - return new ValidationVisitor( - $root, - $this->metadataFactory, - $this->validatorFactory, - $this->translator, - $this->translationDomain, - $this->objectInitializers - ); - } - - /** - * @param null|string|string[] $groups - * - * @return string[] - */ - private function resolveGroups($groups) - { - return $groups ? (array) $groups : array(Constraint::DEFAULT_GROUP); - } -} diff --git a/src/Symfony/Component/Validator/Validator/LegacyValidator.php b/src/Symfony/Component/Validator/Validator/LegacyValidator.php deleted file mode 100644 index e35f4c91401b3..0000000000000 --- a/src/Symfony/Component/Validator/Validator/LegacyValidator.php +++ /dev/null @@ -1,29 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator\Validator; - -@trigger_error('The '.__NAMESPACE__.'\LegacyValidator class is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED); - -/** - * A validator that supports both the API of Symfony < 2.5 and Symfony 2.5+. - * - * @since 2.5 - * - * @author Bernhard Schussek - * - * @see \Symfony\Component\Validator\ValidatorInterface - * @see \Symfony\Component\Validator\Validator\ValidatorInterface - * @deprecated since version 2.5, to be removed in 3.0. - */ -class LegacyValidator extends RecursiveValidator -{ -} diff --git a/src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php b/src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php index d632d05d3f4e3..d8fcc15e8af66 100644 --- a/src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php +++ b/src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php @@ -22,11 +22,11 @@ use Symfony\Component\Validator\Exception\ValidatorException; use Symfony\Component\Validator\Mapping\CascadingStrategy; use Symfony\Component\Validator\Mapping\ClassMetadataInterface; +use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface; use Symfony\Component\Validator\Mapping\GenericMetadata; use Symfony\Component\Validator\Mapping\MetadataInterface; use Symfony\Component\Validator\Mapping\PropertyMetadataInterface; use Symfony\Component\Validator\Mapping\TraversalStrategy; -use Symfony\Component\Validator\MetadataFactoryInterface; use Symfony\Component\Validator\ObjectInitializerInterface; use Symfony\Component\Validator\Util\PropertyPath; @@ -181,17 +181,6 @@ public function validateProperty($object, $propertyName, $groups = null) { $classMetadata = $this->metadataFactory->getMetadataFor($object); - if (!$classMetadata instanceof ClassMetadataInterface) { - // Cannot be UnsupportedMetadataException because of BC with - // Symfony < 2.5 - throw new ValidatorException(sprintf( - 'The metadata factory should return instances of '. - '"\Symfony\Component\Validator\Mapping\ClassMetadataInterface", '. - 'got: "%s".', - is_object($classMetadata) ? get_class($classMetadata) : gettype($classMetadata) - )); - } - $propertyMetadatas = $classMetadata->getPropertyMetadata($propertyName); $groups = $groups ? $this->normalizeGroups($groups) : $this->defaultGroups; $cacheKey = spl_object_hash($object); diff --git a/src/Symfony/Component/Validator/Validator/RecursiveValidator.php b/src/Symfony/Component/Validator/Validator/RecursiveValidator.php index e4dc0fb057d29..50d54a07423f2 100644 --- a/src/Symfony/Component/Validator/Validator/RecursiveValidator.php +++ b/src/Symfony/Component/Validator/Validator/RecursiveValidator.php @@ -11,15 +11,11 @@ namespace Symfony\Component\Validator\Validator; -use Symfony\Component\Validator\Constraint; -use Symfony\Component\Validator\Constraints\GroupSequence; -use Symfony\Component\Validator\Constraints\Valid; use Symfony\Component\Validator\ConstraintValidatorFactoryInterface; use Symfony\Component\Validator\Context\ExecutionContextFactoryInterface; use Symfony\Component\Validator\Context\ExecutionContextInterface; -use Symfony\Component\Validator\MetadataFactoryInterface; +use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface; use Symfony\Component\Validator\ObjectInitializerInterface; -use Symfony\Component\Validator\ValidatorInterface as LegacyValidatorInterface; /** * Recursive implementation of {@link ValidatorInterface}. @@ -28,7 +24,7 @@ * * @author Bernhard Schussek */ -class RecursiveValidator implements ValidatorInterface, LegacyValidatorInterface +class RecursiveValidator implements ValidatorInterface { /** * @var ExecutionContextFactoryInterface @@ -115,21 +111,8 @@ public function hasMetadataFor($object) /** * {@inheritdoc} */ - public function validate($value, $groups = null, $traverse = false, $deep = false) + public function validate($value, $constraints = null, $groups = null) { - $numArgs = func_num_args(); - - // Use new signature if constraints are given in the second argument - if (self::testConstraints($groups) && ($numArgs < 3 || 3 === $numArgs && self::testGroups($traverse))) { - // Rename to avoid total confusion ;) - $constraints = $groups; - $groups = $traverse; - } else { - @trigger_error('The Symfony\Component\Validator\ValidatorInterface::validate method is deprecated in version 2.5 and will be removed in version 3.0. Use the Symfony\Component\Validator\Validator\ValidatorInterface::validate method instead.', E_USER_DEPRECATED); - - $constraints = new Valid(array('traverse' => $traverse, 'deep' => $deep)); - } - return $this->startContext($value) ->validate($value, $constraints, $groups) ->getViolations(); @@ -155,34 +138,4 @@ public function validatePropertyValue($objectOrClass, $propertyName, $value, $gr ->validatePropertyValue($objectOrClass, $propertyName, $value, $groups) ->getViolations(); } - - /** - * {@inheritdoc} - */ - public function validateValue($value, $constraints, $groups = null) - { - @trigger_error('The '.__METHOD__.' method is deprecated in version 2.5 and will be removed in version 3.0. Use the Symfony\Component\Validator\Validator\ValidatorInterface::validate method instead.', E_USER_DEPRECATED); - - return $this->validate($value, $constraints, $groups); - } - - /** - * {@inheritdoc} - */ - public function getMetadataFactory() - { - @trigger_error('The '.__METHOD__.' method is deprecated in version 2.5 and will be removed in version 3.0. Use the Symfony\Component\Validator\Validator\ValidatorInterface::getMetadataFor or Symfony\Component\Validator\Validator\ValidatorInterface::hasMetadataFor method instead.', E_USER_DEPRECATED); - - return $this->metadataFactory; - } - - private static function testConstraints($constraints) - { - return null === $constraints || $constraints instanceof Constraint || (is_array($constraints) && (0 === count($constraints) || current($constraints) instanceof Constraint)); - } - - private static function testGroups($groups) - { - return null === $groups || is_string($groups) || $groups instanceof GroupSequence || (is_array($groups) && (0 === count($groups) || is_string(current($groups)) || current($groups) instanceof GroupSequence)); - } } diff --git a/src/Symfony/Component/Validator/ValidatorBuilder.php b/src/Symfony/Component/Validator/ValidatorBuilder.php index 4a69976ed2b11..fc3abd342355f 100644 --- a/src/Symfony/Component/Validator/ValidatorBuilder.php +++ b/src/Symfony/Component/Validator/ValidatorBuilder.php @@ -19,10 +19,10 @@ use Symfony\Component\Translation\IdentityTranslator; use Symfony\Component\Translation\TranslatorInterface; use Symfony\Component\Validator\Context\ExecutionContextFactory; -use Symfony\Component\Validator\Exception\InvalidArgumentException; use Symfony\Component\Validator\Exception\ValidatorException; use Symfony\Component\Validator\Mapping\Cache\CacheInterface; use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory; +use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; use Symfony\Component\Validator\Mapping\Loader\LoaderChain; use Symfony\Component\Validator\Mapping\Loader\StaticMethodLoader; @@ -292,41 +292,6 @@ public function setTranslationDomain($translationDomain) return $this; } - /** - * {@inheritdoc} - * - * @deprecated since version 2.5, to be removed in 3.0. - * The validator will function without a property accessor. - */ - public function setPropertyAccessor(PropertyAccessorInterface $propertyAccessor) - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0. The validator will function without a property accessor.', E_USER_DEPRECATED); - - if (null !== $this->validatorFactory) { - throw new ValidatorException('You cannot set a property accessor after setting a custom validator factory. Configure your validator factory instead.'); - } - - $this->propertyAccessor = $propertyAccessor; - - return $this; - } - - /** - * {@inheritdoc} - * - * @deprecated since version 2.7, to be removed in 3.0. - */ - public function setApiVersion($apiVersion) - { - @trigger_error('The '.__METHOD__.' method is deprecated in version 2.7 and will be removed in version 3.0.', E_USER_DEPRECATED); - - if (!in_array($apiVersion, array(Validation::API_VERSION_2_4, Validation::API_VERSION_2_5, Validation::API_VERSION_2_5_BC))) { - throw new InvalidArgumentException(sprintf('The requested API version is invalid: "%s"', $apiVersion)); - } - - return $this; - } - /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/Validator/ValidatorBuilderInterface.php b/src/Symfony/Component/Validator/ValidatorBuilderInterface.php index e15fb7aa14e67..918c8be392dfb 100644 --- a/src/Symfony/Component/Validator/ValidatorBuilderInterface.php +++ b/src/Symfony/Component/Validator/ValidatorBuilderInterface.php @@ -12,9 +12,9 @@ namespace Symfony\Component\Validator; use Doctrine\Common\Annotations\Reader; -use Symfony\Component\PropertyAccess\PropertyAccessorInterface; use Symfony\Component\Translation\TranslatorInterface; use Symfony\Component\Validator\Mapping\Cache\CacheInterface; +use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface; /** * A configurable builder for ValidatorInterface objects. @@ -160,30 +160,6 @@ public function setTranslator(TranslatorInterface $translator); */ public function setTranslationDomain($translationDomain); - /** - * Sets the property accessor for resolving property paths. - * - * @param PropertyAccessorInterface $propertyAccessor The property accessor - * - * @return ValidatorBuilderInterface The builder object - * - * @deprecated since version 2.5, to be removed in 3.0. - */ - public function setPropertyAccessor(PropertyAccessorInterface $propertyAccessor); - - /** - * Sets the API version that the returned validator should support. - * - * @param int $apiVersion The required API version - * - * @return ValidatorBuilderInterface The builder object - * - * @see Validation::API_VERSION_2_5 - * @see Validation::API_VERSION_2_5_BC - * @deprecated since version 2.7, to be removed in 3.0. - */ - public function setApiVersion($apiVersion); - /** * Builds and returns a new validator object. * diff --git a/src/Symfony/Component/Validator/ValidatorInterface.php b/src/Symfony/Component/Validator/ValidatorInterface.php deleted file mode 100644 index 3682b15be6116..0000000000000 --- a/src/Symfony/Component/Validator/ValidatorInterface.php +++ /dev/null @@ -1,115 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator; - -/** - * Validates values and graphs of objects and arrays. - * - * @author Bernhard Schussek - * - * @api - * - * @deprecated since version 2.5, to be removed in 3.0. - * Use {@link \Symfony\Component\Validator\Validator\ValidatorInterface} instead. - */ -interface ValidatorInterface -{ - /** - * Validates a value. - * - * The accepted values depend on the {@link MetadataFactoryInterface} - * implementation. - * - * The signature changed with Symfony 2.5 (see - * {@link Validator\ValidatorInterface::validate()}. This signature will be - * disabled in Symfony 3.0. - * - * @param mixed $value The value to validate - * @param array|null $groups The validation groups to validate. - * @param bool $traverse Whether to traverse the value if it is traversable. - * @param bool $deep Whether to traverse nested traversable values recursively. - * - * @return ConstraintViolationListInterface A list of constraint violations. If the - * list is empty, validation succeeded. - * - * @api - */ - public function validate($value, $groups = null, $traverse = false, $deep = false); - - /** - * Validates a property of a value against its current value. - * - * The accepted values depend on the {@link MetadataFactoryInterface} - * implementation. - * - * @param mixed $containingValue The value containing the property. - * @param string $property The name of the property to validate. - * @param array|null $groups The validation groups to validate. - * - * @return ConstraintViolationListInterface A list of constraint violations. If the - * list is empty, validation succeeded. - * - * @api - */ - public function validateProperty($containingValue, $property, $groups = null); - - /** - * Validate a property of a value against a potential value. - * - * The accepted values depend on the {@link MetadataFactoryInterface} - * implementation. - * - * @param mixed $containingValue The value containing the property. - * @param string $property The name of the property to validate - * @param string $value The value to validate against the - * constraints of the property. - * @param array|null $groups The validation groups to validate. - * - * @return ConstraintViolationListInterface A list of constraint violations. If the - * list is empty, validation succeeded. - * - * @api - */ - public function validatePropertyValue($containingValue, $property, $value, $groups = null); - - /** - * Validates a value against a constraint or a list of constraints. - * - * @param mixed $value The value to validate. - * @param Constraint|Constraint[] $constraints The constraint(s) to validate against. - * @param array|null $groups The validation groups to validate. - * - * @return ConstraintViolationListInterface A list of constraint violations. If the - * list is empty, validation succeeded. - * - * @api - * - * @deprecated since version 2.5, to be removed in 3.0. - * Renamed to {@link Validator\ValidatorInterface::validate()} - * in Symfony 2.5. - */ - public function validateValue($value, $constraints, $groups = null); - - /** - * Returns the factory for metadata instances. - * - * @return MetadataFactoryInterface The metadata factory. - * - * @api - * - * @deprecated since version 2.5, to be removed in 3.0. - * Use {@link Validator\ValidatorInterface::getMetadataFor()} or - * {@link Validator\ValidatorInterface::hasMetadataFor()} - * instead. - */ - public function getMetadataFactory(); -} diff --git a/src/Symfony/Component/Validator/Violation/LegacyConstraintViolationBuilder.php b/src/Symfony/Component/Validator/Violation/LegacyConstraintViolationBuilder.php deleted file mode 100644 index 7410b0a6fc2d7..0000000000000 --- a/src/Symfony/Component/Validator/Violation/LegacyConstraintViolationBuilder.php +++ /dev/null @@ -1,166 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator\Violation; - -@trigger_error('The '.__NAMESPACE__.'\LegacyConstraintViolationBuilder class is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED); - -use Symfony\Component\Validator\ExecutionContextInterface; - -/** - * Backwards-compatible implementation of {@link ConstraintViolationBuilderInterface}. - * - * @author Bernhard Schussek - * - * @internal You should not instantiate or use this class. Code against - * {@link ConstraintViolationBuilderInterface} instead. - * - * @deprecated since version 2.5.5, to be removed in 3.0. - */ -class LegacyConstraintViolationBuilder implements ConstraintViolationBuilderInterface -{ - /** - * @var ExecutionContextInterface - */ - private $context; - - /** - * @var string - */ - private $message; - - /** - * @var array - */ - private $parameters; - - /** - * @var mixed - */ - private $invalidValue; - - /** - * @var string - */ - private $propertyPath; - - /** - * @var int|null - */ - private $plural; - - /** - * @var mixed - */ - private $code; - - public function __construct(ExecutionContextInterface $context, $message, array $parameters) - { - $this->context = $context; - $this->message = $message; - $this->parameters = $parameters; - $this->invalidValue = $context->getValue(); - } - - /** - * {@inheritdoc} - */ - public function atPath($path) - { - $this->propertyPath = $path; - - return $this; - } - - /** - * {@inheritdoc} - */ - public function setParameter($key, $value) - { - $this->parameters[$key] = $value; - - return $this; - } - - /** - * {@inheritdoc} - */ - public function setParameters(array $parameters) - { - $this->parameters = $parameters; - - return $this; - } - - /** - * {@inheritdoc} - */ - public function setTranslationDomain($translationDomain) - { - // can't be set in the old API - - return $this; - } - - /** - * {@inheritdoc} - */ - public function setInvalidValue($invalidValue) - { - $this->invalidValue = $invalidValue; - - return $this; - } - - /** - * {@inheritdoc} - */ - public function setPlural($number) - { - $this->plural = $number; - - return $this; - } - - /** - * {@inheritdoc} - */ - public function setCode($code) - { - $this->code = $code; - - return $this; - } - - /** - * {@inheritdoc} - */ - public function setCause($cause) - { - // do nothing - we can't save the cause through the old API - - return $this; - } - - /** - * {@inheritdoc} - */ - public function addViolation() - { - if ($this->propertyPath) { - $this->context->addViolationAt($this->propertyPath, $this->message, $this->parameters, $this->invalidValue, $this->plural, $this->code); - - return; - } - - $this->context->addViolation($this->message, $this->parameters, $this->invalidValue, $this->plural, $this->code); - } -}