Completed
Push — master ( 51fd8b...a5ed14 )
by
unknown
02:53 queued 12s
created

ObjectAclManipulatorCompilerPass::process()   B

Complexity

Conditions 7
Paths 6

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 8.5706
c 0
b 0
f 0
cc 7
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 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.') || null === $class = $container->getDefinition($id)->getClass()) {
34
                continue;
35
            }
36
37
            // We trim the possible "%" characters around the class definition since it could be using "%parameter%" syntax.
38
            $class = trim($class, '%');
39
40
            if (!class_exists($class, false) && $container->hasParameter($class)) {
41
                $class = $container->getParameter($class);
42
            }
43
44
            if (!is_subclass_of($class, 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...
45
                continue;
46
            }
47
48
            $availableManagers[$id] = $container->getDefinition($id);
49
        }
50
51
        $generateAdminCommandDefinition = $container->getDefinition(GenerateObjectAclCommand::class);
52
        $generateAdminCommandDefinition->replaceArgument(1, $availableManagers);
53
    }
54
}
55