From 61007e345fb3667538cd5ef2a1097a41ecb48ead Mon Sep 17 00:00:00 2001 From: Maxime Steinhausser Date: Wed, 24 May 2017 15:03:25 +0200 Subject: [PATCH] [FrameworkBundle][Validator] Remove deprecated ConstraintValidatorFactory $validators argument --- UPGRADE-4.0.md | 4 +++ .../Bundle/FrameworkBundle/CHANGELOG.md | 1 + .../ConstraintValidatorFactoryTest.php | 28 ------------------- .../Validator/ConstraintValidatorFactory.php | 14 ++-------- 4 files changed, 7 insertions(+), 40 deletions(-) diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md index 70c6f8e7e6413..2e21c20137187 100644 --- a/UPGRADE-4.0.md +++ b/UPGRADE-4.0.md @@ -338,6 +338,10 @@ FrameworkBundle has been removed. Use the `Symfony\Component\Workflow\DependencyInjection\ValidateWorkflowsPass` class instead. + * Passing an array of validators or validator aliases as the second argument + of `ConstraintValidatorFactory::__construct()` has been removed. + Use the service locator instead. + HttpFoundation -------------- diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index 869af4d9059e1..d0460c5bce7ca 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -17,6 +17,7 @@ CHANGELOG * Removed `ConstraintValidatorFactory::$validators` and `ConstraintValidatorFactory::$container` protected properties * Removed class parameters related to routing * Removed absolute template paths support in the template name parser + * Removed `ConstraintValidatorFactory::__construct()` `$validators` argument 3.3.0 ----- diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Validator/ConstraintValidatorFactoryTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Validator/ConstraintValidatorFactoryTest.php index 38a1190aded74..5b8378a63d14b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Validator/ConstraintValidatorFactoryTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Validator/ConstraintValidatorFactoryTest.php @@ -71,34 +71,6 @@ public function testGetInstanceReturnsService() $this->assertSame($validator, $factory->getInstance($constraint)); } - /** - * @group legacy - * @expectedDeprecation Passing an array of validators or validator aliases as the second argument of "Symfony\Bundle\FrameworkBundle\Validator\ConstraintValidatorFactory::__construct" is deprecated since 3.3 and will be removed in 4.0. Use the service locator instead. - */ - public function testGetInstanceReturnsServiceWithAlias() - { - $service = 'validator_constraint_service'; - $alias = 'validator_constraint_alias'; - $validator = $this->getMockForAbstractClass('Symfony\\Component\\Validator\\ConstraintValidator'); - - // mock ContainerBuilder b/c it implements TaggedContainerInterface - $container = $this->getMockBuilder('Symfony\\Component\\DependencyInjection\\ContainerBuilder')->setMethods(array('get'))->getMock(); - $container - ->expects($this->once()) - ->method('get') - ->with($service) - ->will($this->returnValue($validator)); - - $constraint = $this->getMockBuilder('Symfony\\Component\\Validator\\Constraint')->getMock(); - $constraint - ->expects($this->once()) - ->method('validatedBy') - ->will($this->returnValue($alias)); - - $factory = new ConstraintValidatorFactory($container, array('validator_constraint_alias' => 'validator_constraint_service')); - $this->assertSame($validator, $factory->getInstance($constraint)); - } - /** * @expectedException \Symfony\Component\Validator\Exception\ValidatorException */ diff --git a/src/Symfony/Bundle/FrameworkBundle/Validator/ConstraintValidatorFactory.php b/src/Symfony/Bundle/FrameworkBundle/Validator/ConstraintValidatorFactory.php index 5702dcd5a5075..64065712f9cec 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Validator/ConstraintValidatorFactory.php +++ b/src/Symfony/Bundle/FrameworkBundle/Validator/ConstraintValidatorFactory.php @@ -45,17 +45,10 @@ class ConstraintValidatorFactory implements ConstraintValidatorFactoryInterface private $container; private $validators; - public function __construct(ContainerInterface $container, array $validators = null) + public function __construct(ContainerInterface $container) { $this->container = $container; - - if (null !== $validators) { - @trigger_error(sprintf('Passing an array of validators or validator aliases as the second argument of "%s" is deprecated since 3.3 and will be removed in 4.0. Use the service locator instead.', __METHOD__), E_USER_DEPRECATED); - } else { - $validators = array(); - } - - $this->validators = $validators; + $this->validators = array(); } /** @@ -82,9 +75,6 @@ public function getInstance(Constraint $constraint) $this->validators[$name] = new $name(); } - } elseif (is_string($this->validators[$name])) { - // To be removed in 4.0 - $this->validators[$name] = $this->container->get($this->validators[$name]); } if (!$this->validators[$name] instanceof ConstraintValidatorInterface) {