AdapterCompilerPass.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /*
  3. * This file is part of the Sonata Project package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sonata\CoreBundle\DependencyInjection\Compiler;
  11. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\DependencyInjection\Reference;
  14. /**
  15. * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  16. */
  17. class AdapterCompilerPass implements CompilerPassInterface
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public function process(ContainerBuilder $container)
  23. {
  24. if (!$container->has('sonata.core.model.adapter.chain')) {
  25. return;
  26. }
  27. $definition = $container->findDefinition('sonata.core.model.adapter.chain');
  28. if ($container->has('doctrine')) {
  29. $definition->addMethodCall('addAdapter', array(new Reference('sonata.core.model.adapter.doctrine_orm')));
  30. } else {
  31. $container->removeDefinition('sonata.core.model.adapter.doctrine_orm');
  32. }
  33. if ($container->has('doctrine_phpcr')) {
  34. $definition->addMethodCall('addAdapter', array(new Reference('sonata.core.model.adapter.doctrine_phpcr')));
  35. } else {
  36. $container->removeDefinition('sonata.core.model.adapter.doctrine_phpcr');
  37. }
  38. }
  39. }