From 86f9b17254253fc086769c45f4c06cd58e23226c Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Wed, 18 May 2011 23:09:46 +0200 Subject: [PATCH] [Doctrine] Add DoctrineBundle integration (DI Container registration) for the UniqueEntityValidator --- .../AddValidatorNamespaceAliasPass.php | 31 +++++++++++++++++++ .../Bundle/DoctrineBundle/DoctrineBundle.php | 2 ++ .../DoctrineBundle/Resources/config/orm.xml | 9 ++++++ .../DoctrineBundle/Tests/ContainerTest.php | 2 ++ 4 files changed, 44 insertions(+) create mode 100644 src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Compiler/AddValidatorNamespaceAliasPass.php diff --git a/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Compiler/AddValidatorNamespaceAliasPass.php b/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Compiler/AddValidatorNamespaceAliasPass.php new file mode 100644 index 000000000000..5c318bf71296 --- /dev/null +++ b/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Compiler/AddValidatorNamespaceAliasPass.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\DoctrineBundle\DependencyInjection\Compiler; + +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; + +class AddValidatorNamespaceAliasPass implements CompilerPassInterface +{ + public function process(ContainerBuilder $container) + { + if (!$container->hasDefinition('validator.mapping.loader.annotation_loader')) { + return; + } + + $loader = $container->getDefinition('validator.mapping.loader.annotation_loader'); + $args = $container->getParameterBag()->resolveValue($loader->getArguments()); + + $args[0]['assertORM'] = 'Symfony\\Bridge\\Doctrine\\Validator\\Constraints\\'; + $loader->replaceArgument(0, $args[0]); + } +} \ No newline at end of file diff --git a/src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php b/src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php index 0e15ad3aff29..43eb9da0d631 100644 --- a/src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php +++ b/src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php @@ -13,6 +13,7 @@ use Symfony\Component\DependencyInjection\Compiler\PassConfig; use Symfony\Bundle\DoctrineBundle\DependencyInjection\Compiler\RegisterEventListenersAndSubscribersPass; +use Symfony\Bundle\DoctrineBundle\DependencyInjection\Compiler\AddValidatorNamespaceAliasPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; @@ -29,5 +30,6 @@ public function build(ContainerBuilder $container) parent::build($container); $container->addCompilerPass(new RegisterEventListenersAndSubscribersPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION); + $container->addCompilerPass(new AddValidatorNamespaceAliasPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION); } } diff --git a/src/Symfony/Bundle/DoctrineBundle/Resources/config/orm.xml b/src/Symfony/Bundle/DoctrineBundle/Resources/config/orm.xml index 248f90cd4115..3d286153f486 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Resources/config/orm.xml +++ b/src/Symfony/Bundle/DoctrineBundle/Resources/config/orm.xml @@ -31,6 +31,9 @@ Symfony\Bridge\Doctrine\Form\DoctrineOrmTypeGuesser + + + Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntityValidator @@ -60,5 +63,11 @@ + + + + + + diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/ContainerTest.php b/src/Symfony/Bundle/DoctrineBundle/Tests/ContainerTest.php index 6bd973be1b90..3e315036a476 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/ContainerTest.php +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/ContainerTest.php @@ -37,6 +37,8 @@ public function testContainer() $this->assertInstanceOf('Doctrine\Common\EventManager', $container->get('doctrine.dbal.event_manager')); $this->assertInstanceOf('Doctrine\DBAL\Event\Listeners\MysqlSessionInit', $container->get('doctrine.dbal.default_connection.events.mysqlsessioninit')); $this->assertInstanceOf('Symfony\Bundle\DoctrineBundle\CacheWarmer\ProxyCacheWarmer', $container->get('doctrine.orm.proxy_cache_warmer')); + $this->assertInstanceOf('Symfony\Bundle\DoctrineBundle\Registry', $container->get('doctrine')); + $this->assertInstanceOf('Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntityValidator', $container->get('doctrine.orm.validator.unique')); $this->assertSame($container->get('my.platform'), $container->get('doctrine.dbal.default_connection')->getDatabasePlatform());