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\DoctrineMongoDBAdminBundle\DependencyInjection\Compiler; |
15
|
|
|
|
16
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
18
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Thomas Rabaix <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class AddGuesserCompilerPass implements CompilerPassInterface |
24
|
|
|
{ |
25
|
|
|
public function process(ContainerBuilder $container): void |
26
|
|
|
{ |
27
|
|
|
$this->addGuessersToBuilder( |
28
|
|
|
$container, |
29
|
|
|
'sonata.admin.guesser.doctrine_mongodb_list_chain', |
30
|
|
|
'sonata.admin.guesser.doctrine_mongodb_list' |
31
|
|
|
); |
32
|
|
|
|
33
|
|
|
$this->addGuessersToBuilder( |
34
|
|
|
$container, |
35
|
|
|
'sonata.admin.guesser.doctrine_mongodb_datagrid_chain', |
36
|
|
|
'sonata.admin.guesser.doctrine_mongodb_datagrid' |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
$this->addGuessersToBuilder( |
40
|
|
|
$container, |
41
|
|
|
'sonata.admin.guesser.doctrine_mongodb_show_chain', |
42
|
|
|
'sonata.admin.guesser.doctrine_mongodb_show' |
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
private function addGuessersToBuilder(ContainerBuilder $container, string $builderDefinitionId, string $guessersTag): void |
47
|
|
|
{ |
48
|
|
|
if (!$container->hasDefinition($builderDefinitionId)) { |
49
|
|
|
return; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$definition = $container->getDefinition($builderDefinitionId); |
53
|
|
|
$services = []; |
54
|
|
|
foreach ($container->findTaggedServiceIds($guessersTag) as $id => $attributes) { |
55
|
|
|
$services[] = new Reference($id); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$definition->replaceArgument(0, $services); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|