|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Everlution\NavigationBundle\DependencyInjection\Compiler; |
|
6
|
|
|
|
|
7
|
|
|
use Everlution\Navigation\Item\RegistrableItemInterface; |
|
8
|
|
|
use Everlution\Navigation\Registry; |
|
9
|
|
|
use Everlution\NavigationBundle\Bridge\Item\Container\ItemContainer; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
11
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
12
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
13
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class RegisterStandaloneItemsCompilerPass. |
|
17
|
|
|
* |
|
18
|
|
|
* @author Ivan Barlog <[email protected]> |
|
19
|
|
|
*/ |
|
20
|
|
|
class RegisterStandaloneItemsCompilerPass implements CompilerPassInterface |
|
21
|
|
|
{ |
|
22
|
|
|
public function process(ContainerBuilder $container) |
|
23
|
|
|
{ |
|
24
|
|
|
$registry = $container->findDefinition(Registry::class); |
|
25
|
|
|
$itemsContainer = $container->findDefinition(ItemContainer::class); |
|
26
|
|
|
$services = $container->findTaggedServiceIds('everlution.navigation_item'); |
|
27
|
|
|
|
|
28
|
|
|
foreach ($services as $id => $tags) { |
|
29
|
|
|
$alias = $tags[0]['alias'] ?? null; |
|
30
|
|
|
|
|
31
|
|
|
if (null === $alias) { |
|
32
|
|
|
continue; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
$itemsContainer->addMethodCall( |
|
36
|
|
|
'addItem', |
|
37
|
|
|
[$alias, new Reference($id)] |
|
38
|
|
|
); |
|
39
|
|
|
|
|
40
|
|
|
$this->registerItem($id, $container, $registry); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
private function registerItem(string $id, ContainerBuilder $container, Definition $registry) |
|
45
|
|
|
{ |
|
46
|
|
|
$definition = $container->findDefinition($id); |
|
47
|
|
|
$class = $definition->getClass(); |
|
48
|
|
|
|
|
49
|
|
|
$reflectionClass = $container->getReflectionClass($class); |
|
50
|
|
|
if ($reflectionClass->implementsInterface(RegistrableItemInterface::class)) { |
|
51
|
|
|
$registry->addMethodCall('register', [new Reference($id)]); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|