Completed
Pull Request — master (#6210)
by Jordi Sala
37:29
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
 * @final since sonata-project/admin-bundle 3.52
23
 *
24
 * @author Gaurav Singh Faudjdar <[email protected]>
25
 */
26
final class ModelManagerCompilerPass implements CompilerPassInterface
27
{
28
    public const MANAGER_TAG = 'sonata.admin.manager';
29
30
    public function process(ContainerBuilder $container): void
31
    {
32
        $availableManagers = [];
33
34
        foreach ($container->findTaggedServiceIds(self::MANAGER_TAG) as $id => $tags) {
35
            $availableManagers[$id] = $container->findDefinition($id);
36
        }
37
38
        if (!empty($availableManagers)) {
39
            $bundles = $container->getParameter('kernel.bundles');
40
            if (isset($bundles['MakerBundle'])) {
41
                $adminMakerDefinition = $container->getDefinition('sonata.admin.maker');
42
                $adminMakerDefinition->replaceArgument(1, $availableManagers);
43
            }
44
        }
45
    }
46
}
47