Completed
Pull Request — master (#6210)
by Jordi Sala
52:30 queued 07:01
created

ModelManagerCompilerPass::process()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 4
nc 6
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\DependencyInjection\Compiler;
15
16
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
19
/**
20
 * This class injects available model managers to services which depend on them.
21
 *
22
 * @author Gaurav Singh Faudjdar <[email protected]>
23
 */
24
final class ModelManagerCompilerPass implements CompilerPassInterface
25
{
26
    public const MANAGER_TAG = 'sonata.admin.manager';
27
28
    public function process(ContainerBuilder $container): void
29
    {
30
        $availableManagers = [];
31
32
        foreach ($container->findTaggedServiceIds(self::MANAGER_TAG) as $id => $tags) {
33
            $availableManagers[$id] = $container->findDefinition($id);
34
        }
35
36
        if (!empty($availableManagers)) {
37
            $bundles = $container->getParameter('kernel.bundles');
38
            if (isset($bundles['MakerBundle'])) {
39
                $adminMakerDefinition = $container->getDefinition('sonata.admin.maker');
40
                $adminMakerDefinition->replaceArgument(1, $availableManagers);
41
            }
42
        }
43
    }
44
}
45