Completed
Push — master ( 8be640...eaa368 )
by Aaron
22:16
created

ServiceAliasCompilerPass   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 21
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 12 2
1
<?php
2
3
/*
4
 * This file is part of cache-bundle.
5
 *
6
 * (c) Aaron Scherer <[email protected]>
7
 *
8
 * This source file is subject to the license that is bundled
9
 * with this source code in the file LICENSE
10
 */
11
12
namespace Cache\AdapterBundle\DependencyInjection\CompilerPass;
13
14
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
17
/**
18
 * @author Aaron Scherer <[email protected]>
19
 *
20
 * ServiceAliasCompilerPass Class
21
 */
22
class ServiceAliasCompilerPass implements CompilerPassInterface
23
{
24
25
    /**
26
     * You can modify the container here before it is dumped to PHP code.
27
     *
28
     * @param ContainerBuilder $container
29
     */
30
    public function process(ContainerBuilder $container)
31
    {
32
        $serviceIds = array_keys($container->findTaggedServiceIds('cache.provider'));
33
        foreach ($serviceIds as $serviceId) {
34
            $cleanName = str_replace('.inner', '', $serviceId);
35
            $instance  = $container->get($serviceId);
36
            $class     = get_class($instance);
37
38
            $container->setAlias($cleanName, $serviceId);
39
            $container->setAlias($class, $cleanName);
40
        }
41
    }
42
}
43