|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Khusseini\PimcoreRadBrickBundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Khusseini\PimcoreRadBrickBundle\AreabrickConfigurator; |
|
6
|
|
|
use Khusseini\PimcoreRadBrickBundle\AreabrickRenderer; |
|
7
|
|
|
use Khusseini\PimcoreRadBrickBundle\Areabricks\SimpleBrick; |
|
8
|
|
|
use Symfony\Component\Config\FileLocator; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\ChildDefinition; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
11
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
12
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
|
13
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
14
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
15
|
|
|
|
|
16
|
|
|
class PimcoreRadBrickExtension extends Extension |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @param array<array> $configs |
|
20
|
|
|
* |
|
21
|
|
|
* @return void |
|
22
|
|
|
*/ |
|
23
|
3 |
|
public function load(array $configs, ContainerBuilder $container) |
|
24
|
|
|
{ |
|
25
|
3 |
|
$loader = new YamlFileLoader($container, new FileLocator(\dirname(__DIR__).'/Resources/config')); |
|
26
|
3 |
|
$loader->load('services.yml'); |
|
27
|
|
|
|
|
28
|
3 |
|
$configuration = new Configuration(); |
|
29
|
3 |
|
$config = $this->processConfiguration($configuration, $configs); |
|
30
|
|
|
|
|
31
|
3 |
|
$configurators = []; |
|
32
|
3 |
|
$ids = $container->findTaggedServiceIds('radbrick.configurator'); |
|
33
|
3 |
|
foreach ($ids as $id => $tags) { |
|
34
|
3 |
|
$configurators[] = new Reference($id); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
3 |
|
$datasources = $config['datasources']; |
|
38
|
3 |
|
foreach ($datasources as $key => $datasource) { |
|
39
|
1 |
|
$datasources[$key]['service_id'] = new Reference($datasource['service_id']); |
|
40
|
|
|
} |
|
41
|
3 |
|
$config['datasources'] = $datasources; |
|
42
|
|
|
|
|
43
|
3 |
|
$configurator = new Definition( |
|
44
|
3 |
|
AreabrickConfigurator::class, |
|
45
|
|
|
[ |
|
46
|
3 |
|
$config, |
|
47
|
3 |
|
$configurators, |
|
48
|
|
|
] |
|
49
|
|
|
); |
|
50
|
3 |
|
$container->setDefinition(AreabrickConfigurator::class, $configurator); |
|
51
|
|
|
|
|
52
|
3 |
|
$rendererDefinition = new Definition(AreabrickRenderer::class, [ |
|
53
|
3 |
|
new Reference(AreabrickConfigurator::class), |
|
54
|
3 |
|
new Reference('pimcore.templating.tag_renderer'), |
|
55
|
|
|
]); |
|
56
|
|
|
|
|
57
|
3 |
|
$container->setDefinition(AreabrickRenderer::class, $rendererDefinition); |
|
58
|
|
|
|
|
59
|
3 |
|
$areabricks = $config['areabricks']; |
|
60
|
3 |
|
foreach ($areabricks as $id => $areabrickConfig) { |
|
61
|
3 |
|
$definitionId = 'radbrick.'.$id; |
|
62
|
3 |
|
$parent = null; |
|
|
|
|
|
|
63
|
3 |
|
$options = $areabrickConfig['options'] ?: []; |
|
64
|
|
|
|
|
65
|
3 |
|
$target = null; |
|
66
|
3 |
|
if ($class = @$areabrickConfig['class']) { |
|
67
|
1 |
|
$target = new ChildDefinition($class); |
|
68
|
1 |
|
$target->setClass($class); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
3 |
|
if (!$target) { |
|
72
|
2 |
|
$target = new Definition(SimpleBrick::class); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
3 |
|
$target->setArgument('$name', $id); |
|
76
|
3 |
|
$target->setArgument('$areabrickRenderer', new Reference(AreabrickRenderer::class)); |
|
77
|
3 |
|
$target->addMethodCall('configure', [$options]); |
|
78
|
|
|
|
|
79
|
3 |
|
if (!$target->hasTag('pimcore.area.brick')) { |
|
80
|
3 |
|
$target->addTag('pimcore.area.brick', ['id' => $id]); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
3 |
|
$container->setDefinition($definitionId, $target); |
|
84
|
|
|
} |
|
85
|
3 |
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|