Completed
Pull Request — master (#719)
by
unknown
07:43
created

ServiceRepositoryCompilerPass::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Doctrine Bundle
5
 *
6
 * The code was originally distributed inside the Symfony framework.
7
 *
8
 * (c) Fabien Potencier <[email protected]>
9
 * (c) Doctrine Project, Benjamin Eberlei <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler;
16
17
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
use Symfony\Component\DependencyInjection\Reference;
20
21
/**
22
 * @author Ryan Weaver <[email protected]>
23
 */
24
class ServiceRepositoryCompilerPass implements CompilerPassInterface
25
{
26
    const REPOSITORY_SERVICE_TAG = 'doctrine.repository_service';
27
28
    public function process(ContainerBuilder $container)
29
    {
30
        if (!$container->hasDefinition('doctrine.orm.container_repository_factory')) {
31
            return;
32
        }
33
34
        $locatorDef = $container->findDefinition($container->getDefinition('doctrine.orm.container_repository_factory')->getArgument(0));
35
        $repoServiceIds = array_keys($container->findTaggedServiceIds('doctrine.repository_service'));
36
        $repoReferences = array_map(function($id) {
37
            return new Reference($id);
38
        }, $repoServiceIds);
39
        $locatorDef->replaceArgument(0, array_combine($repoServiceIds, $repoReferences));
40
    }
41
}
42