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\Model\ModelManagerInterface; |
17
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
19
|
|
|
use Symfony\Component\DependencyInjection\Exception\LogicException; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* This class injects available model managers to services which depend on them. |
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
|
|
|
$definition = $container->findDefinition($id); |
36
|
|
|
|
37
|
|
|
if (!is_subclass_of($definition->getClass(), ModelManagerInterface::class)) { |
|
|
|
|
38
|
|
|
throw new LogicException(sprintf( |
39
|
|
|
'Service "%s" must implement `%s`.', |
40
|
|
|
$id, |
41
|
|
|
ModelManagerInterface::class |
42
|
|
|
)); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$availableManagers[$id] = $definition; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
if (!empty($availableManagers)) { |
49
|
|
|
$bundles = $container->getParameter('kernel.bundles'); |
50
|
|
|
if (isset($bundles['MakerBundle'])) { |
51
|
|
|
$adminMakerDefinition = $container->getDefinition('sonata.admin.maker'); |
52
|
|
|
$adminMakerDefinition->replaceArgument(1, $availableManagers); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|