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)) { |
|
|
|
|
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
|
|
|
|