|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Framework\Core\DependencyInjection\Compiler; |
|
4
|
|
|
|
|
5
|
|
|
use eXpansion\Framework\Core\Services\PluginManager; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* PluginPass to register all plugins to the plugin manager. |
|
11
|
|
|
* |
|
12
|
|
|
* @package eXpansion\Framework\Core\DependencyInjection\Compiler |
|
13
|
|
|
*/ |
|
14
|
|
|
class PluginPass implements CompilerPassInterface |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Register all data providers to the Manager. |
|
18
|
|
|
* |
|
19
|
|
|
* @param ContainerBuilder $container |
|
20
|
|
|
*/ |
|
21
|
|
|
public function process(ContainerBuilder $container) |
|
22
|
|
|
{ |
|
23
|
|
|
if (!$container->has(PluginManager::class)) { |
|
24
|
|
|
return; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
$pluginsData = []; |
|
28
|
|
|
|
|
29
|
|
|
// Find all Plugin services. |
|
30
|
|
|
$plugins = $container->findTaggedServiceIds('expansion.plugin'); |
|
31
|
|
|
foreach ($plugins as $id => $tags) { |
|
32
|
|
|
$pluginsData[$id]['dataProviders'] = []; |
|
33
|
|
|
foreach ($tags as $attributes) { |
|
34
|
|
|
if (isset($attributes['data_provider'])) { |
|
35
|
|
|
$pluginsData[$id]['dataProviders'][] = $attributes['data_provider']; |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
// Find the parent services. |
|
41
|
|
|
$plugins = $container->findTaggedServiceIds('expansion.plugin.parent'); |
|
42
|
|
|
foreach ($plugins as $id => $tags) { |
|
43
|
|
|
foreach ($tags as $attributes) { |
|
44
|
|
|
$pluginsData[$id]['parent'][] = $attributes['parent']; |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
// Get the data provider manager service definition to register data providers into. |
|
49
|
|
|
$definition = $container->getDefinition(PluginManager::class); |
|
50
|
|
|
|
|
51
|
|
|
foreach ($pluginsData as $pluginId => $data) |
|
52
|
|
|
{ |
|
53
|
|
|
$definition->addMethodCall('registerPlugin', [ |
|
54
|
|
|
$pluginId, |
|
55
|
|
|
empty($data['dataProviders']) ? [] : $data['dataProviders'], |
|
56
|
|
|
empty($data['parent']) ? [] : $data['parent'], |
|
57
|
|
|
] |
|
58
|
|
|
); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|