Completed
Pull Request — master (#719)
by
unknown
02:11
created

ServiceRepositoryCompilerPass   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 20
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 15 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\Compiler\ServiceLocatorTagPass;
19
use Symfony\Component\DependencyInjection\ContainerBuilder;
20
use Symfony\Component\DependencyInjection\Reference;
21
22
/**
23
 * @author Ryan Weaver <[email protected]>
24
 */
25
class ServiceRepositoryCompilerPass implements CompilerPassInterface
26
{
27
    const REPOSITORY_SERVICE_TAG = 'doctrine.repository_service';
28
29
    public function process(ContainerBuilder $container)
30
    {
31
        if (!$container->hasDefinition('doctrine.orm.container_repository_factory')) {
32
            return;
33
        }
34
35
        $locatorDef = $container->getDefinition('doctrine.orm.container_repository_factory');
36
        $repoServiceIds = array_keys($container->findTaggedServiceIds(self::REPOSITORY_SERVICE_TAG));
37
        $repoReferences = array_map(function($id) {
38
            return new Reference($id);
39
        }, $repoServiceIds);
40
41
        $ref = ServiceLocatorTagPass::register($container, array_combine($repoServiceIds, $repoReferences));
42
        $locatorDef->replaceArgument(0, $ref);
43
    }
44
}
45