EntityManagerCompilerPass::process()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
1
<?php
2
3
4
namespace Jarobe\TaskRunnerBundle\DependencyInjection\Compiler;
5
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Reference;
9
10
class EntityManagerCompilerPass implements CompilerPassInterface
11
{
12
13
    /**
14
     * You can modify the container here before it is dumped to PHP code.
15
     *
16
     * @param ContainerBuilder $container
17
     */
18
    public function process(ContainerBuilder $container)
19
    {
20
        $entityManagerName = $container->getParameter('jarobe.task_runner.entity_manager');
21
        if ($entityManagerName === null) {
22
            $entityManagerName = 'doctrine.orm.entity_manager';
23
        }
24
        $entityManagerReference = new Reference($entityManagerName);
25
26
        $taskEventManagerDefinition = $container->getDefinition('jarobe.task_runner.task_event_manager');
27
        $taskEventManagerDefinition->replaceArgument(0, $entityManagerReference);
28
29
        $taskEventRepository = $container->getDefinition('jarobe.task_runner.task_event_repository');
30
        $taskEventRepository->setFactory([$entityManagerReference, 'getRepository']);
31
    }
32
}
33