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

ServiceRepositoryCompilerPass   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 18
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 13 2
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