Completed
Pull Request — master (#90)
by Arnaud
19:08
created

DataProviderCompilerPass::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 0
cts 17
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 10
nc 3
nop 1
crap 12
1
<?php
2
3
namespace LAG\AdminBundle\DependencyInjection\CompilerPass;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
class DataProviderCompilerPass implements CompilerPassInterface
10
{
11
    /**
12
     * Add the tagged data provider to the DataProviderFactory.
13
     *
14
     * @param ContainerBuilder $container
15
     */
16
    public function process(ContainerBuilder $container)
17
    {
18
        if (!$container->has('lag.admin.data_providers_factory')) {
19
            return;
20
        }
21
22
        $definition = $container->findDefinition('lag.admin.data_providers_factory');
23
        $taggedServices = $container->findTaggedServiceIds('data_provider');
24
25
        foreach ($taggedServices as $id => $tags) {
26
            $definition->addMethodCall(
27
                'addDataProvider',
28
                [
29
                    $id,
30
                    new Reference($id),
31
                ]
32
            );
33
        }
34
    }
35
}
36