Completed
Push — master ( e6c9d7...cc6bd7 )
by Grégoire
12:23
created

ObjectAclManipulatorCompilerPass::process()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 4
nc 3
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 Sonata\AdminBundle\Command\GenerateObjectAclCommand;
17
use Sonata\AdminBundle\Util\ObjectAclManipulatorInterface;
18
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
19
use Symfony\Component\DependencyInjection\ContainerBuilder;
20
21
/**
22
 * This class injects available object ACL manipulators to services which depend on them.
23
 *
24
 * @author Javier Spagnoletti <[email protected]>
25
 */
26
final class ObjectAclManipulatorCompilerPass implements CompilerPassInterface
27
{
28
    public function process(ContainerBuilder $container): void
29
    {
30
        $availableManagers = [];
31
32
        foreach ($container->getServiceIds() as $id) {
33
            if (0 !== strpos($id, 'sonata.admin.manipulator.acl.object.') || !is_subclass_of($container->getDefinition($id)->getClass(), ObjectAclManipulatorInterface::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Sonata\AdminBundle\Util...pulatorInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
34
                continue;
35
            }
36
37
            $availableManagers[$id] = $container->getDefinition($id);
38
        }
39
40
        $generateAdminCommandDefinition = $container->getDefinition(GenerateObjectAclCommand::class);
41
        $generateAdminCommandDefinition->replaceArgument(1, $availableManagers);
42
    }
43
}
44