diff --git a/src/Symfony/Component/Validator/Extension/DependencyInjectionValidatorFactory.php b/src/Symfony/Component/Validator/Extension/DependencyInjectionValidatorFactory.php deleted file mode 100644 index 84d97c783816..000000000000 --- a/src/Symfony/Component/Validator/Extension/DependencyInjectionValidatorFactory.php +++ /dev/null @@ -1,82 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\Validator\ConstraintValidatorFactoryInterface; -use Symfony\Component\Validator\Constraint; -use Symfony\Component\Validator\ConstraintValidatorInterface; - -/** - * Creates ConstraintValidator instances by querying a dependency injection - * container - * - * The constraint validators are expected to be services. The services should - * have the fully qualified names of the validators as IDs. The backslashes - * in the names should be replaced by dots. - * - * @author Bulat Shakirzyanov - * @author Bernhard Schussek - */ -class DependencyInjectionValidatorFactory implements ConstraintValidatorFactoryInterface -{ - - protected $container; - - /** - * @param ContainerInterface $container - */ - public function __construct(ContainerInterface $container) - { - $this->container = $container; - } - - /** - * Returns a contraint validator from the container service, setting it if it - * doesn't exist yet - * - * Throws an exception if validator service is not instance of - * ConstraintValidatorInterface. - * - * @param Constraint $constraint - * @return ConstraintValidatorInterface - * @throws \LogicException - */ - public function getInstance(Constraint $constraint) - { - $className = $constraint->validatedBy(); - $id = $this->getServiceIdFromClass($className); - - if (!$this->container->has($id)) { - $this->container->set($id, new $className()); - } - - $validator = $this->container->get($id); - - if (!$validator instanceof ConstraintValidatorInterface) { - throw new \LogicException('Service "' . $id . '" is not instance of ConstraintValidatorInterface'); - } - - return $validator; - } - - /** - * Returns the matching service ID for the given validator class name - * - * @param string $className - * @return string - */ - protected function getServiceIdFromClass($className) - { - return str_replace('\\', '.', $className); - } -} \ No newline at end of file diff --git a/tests/Symfony/Tests/Component/Validator/DependencyInjectionValidatorFactoryTest.php b/tests/Symfony/Tests/Component/Validator/DependencyInjectionValidatorFactoryTest.php deleted file mode 100644 index 970b9002d1ce..000000000000 --- a/tests/Symfony/Tests/Component/Validator/DependencyInjectionValidatorFactoryTest.php +++ /dev/null @@ -1,58 +0,0 @@ -container = new Container(); - $this->factory = new DependencyInjectionValidatorFactory($this->container); - } - - public function tearDown() - { - unset ($this->factory); - unset ($this->container); - } - - public function testGetInstanceRetunsCorrectValidatorInstance() - { - $constraint = new Valid(); - $validator = $this->factory->getInstance($constraint); - $this->assertTrue($validator instanceof ValidValidator); - } - - public function testGetInstanceAddsValidatorServiceToContainer() - { - $constraint = new Valid(); - $validator = $this->factory->getInstance($constraint); - $this->assertServiceExists('Symfony.Component.Validator.Constraints.ValidValidator'); - } - - public function assertServiceExists($id) - { - $this->assertTrue($this->container->has($id), 'Service ' . $id . ' doesn\'t exist on container'); - } - - /** - * @expectedException LogicException - */ - public function testGetInstanceThrowsLogicExceptionIfValidatorNotInstanceOfValidatorInterface() - { - $constraint = new InvalidConstraint(); - $validator = $this->factory->getInstance($constraint); - } -} diff --git a/tests/Symfony/Tests/Component/Validator/Extension/DependencyInjectionValidatorFactoryTest.php b/tests/Symfony/Tests/Component/Validator/Extension/DependencyInjectionValidatorFactoryTest.php deleted file mode 100644 index 397d286b3fd5..000000000000 --- a/tests/Symfony/Tests/Component/Validator/Extension/DependencyInjectionValidatorFactoryTest.php +++ /dev/null @@ -1,58 +0,0 @@ -container = new Container(); - $this->factory = new DependencyInjectionValidatorFactory($this->container); - } - - public function tearDown() - { - unset($this->factory); - unset($this->container); - } - - public function testGetInstanceRetunsCorrectValidatorInstance() - { - $constraint = new Valid(); - $validator = $this->factory->getInstance($constraint); - $this->assertTrue($validator instanceof ValidValidator); - } - - public function testGetInstanceAddsValidatorServiceToContainer() - { - $constraint = new Valid(); - $validator = $this->factory->getInstance($constraint); - $this->assertServiceExists('Symfony.Component.Validator.Constraints.ValidValidator'); - } - - private function assertServiceExists($id) - { - $this->assertTrue($this->container->has($id), 'Service ' . $id . ' doesn\'t exist on container'); - } - - /** - * @expectedException LogicException - */ - public function testGetInstanceThrowsLogicExceptionIfValidatorNotInstanceOfValidatorInterface() - { - $constraint = new InvalidConstraint(); - $validator = $this->factory->getInstance($constraint); - } -}