1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
-
-
-
- namespace JMS\DiExtraBundle\DependencyInjection\Compiler;
-
- use Symfony\Component\DependencyInjection\DefinitionDecorator;
- use Symfony\Component\DependencyInjection\Reference;
- use Symfony\Component\DependencyInjection\Alias;
- use Symfony\Component\DependencyInjection\ContainerBuilder;
- use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
-
-
- class IntegrationPass implements CompilerPassInterface
- {
- public function process(ContainerBuilder $container)
- {
-
- $container->setAlias('controller_resolver', new Alias('jms_di_extra.controller_resolver', false));
-
- if (true === $container->getParameter('jms_di_extra.doctrine_integration')) {
- $this->integrateWithDoctrine($container);
- }
- }
-
-
-
- private function integrateWithDoctrine($container)
- {
- foreach ($container->getDefinitions() as $id => $definition) {
- if (!$definition instanceof DefinitionDecorator) {
- continue;
- }
-
- if ('doctrine.orm.entity_manager.abstract' !== $definition->getParent()) {
- continue;
- }
-
- $definition->setPublic(false);
- $container->setDefinition($id.'.delegate', $definition);
- $container->register($id, $container->getParameter('jms_di_extra.doctrine_integration.entity_manager.class'))
- ->setFile($container->getParameter('jms_di_extra.doctrine_integration.entity_manager.file'))
- ->addArgument(new Reference($id.'.delegate'))
- ->addArgument(new Reference('service_container'));
- }
- }
- }
|