8000 [FrameworkBundle][Validator] Remove deprecated ConstraintValidatorFactory by ogizanagi · Pull Request #22887 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle][Validator] Remove deprecated ConstraintValidatorFactory #22887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions UPGRADE-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------

Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand All @@ -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) {
Expand Down
0