|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Framework\MlComposeBundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use eXpansion\Framework\MlComposeBundle\Configuration; |
|
6
|
|
|
use Oliverde8\PageCompose\Block\BlockDefinition; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
|
9
|
|
|
use Symfony\Component\ExpressionLanguage\ExpressionLanguage; |
|
10
|
|
|
use Symfony\Component\Finder\Finder; |
|
11
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
12
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class eXpansionMlComposeExtension |
|
17
|
|
|
* |
|
18
|
|
|
* @author de Cramer Oliver<[email protected]> |
|
19
|
|
|
* @copyright 2018 Oliverde8 |
|
20
|
|
|
* @package eXpansion\Framework\MlComposeBundle\DependencyInjection |
|
21
|
|
|
*/ |
|
22
|
|
|
class eXpansionMlComposeExtension extends Extension implements PrependExtensionInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @inheritdoc |
|
26
|
|
|
*/ |
|
27
|
|
|
public function prepend(ContainerBuilder $container) |
|
28
|
|
|
{ |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
$bundles = $container->getParameter('kernel.bundles'); |
|
32
|
|
|
$finder = new Finder(); |
|
33
|
|
|
|
|
34
|
|
|
foreach ($bundles as $bundle) { |
|
35
|
|
|
$reflection = new \ReflectionClass($bundle); |
|
36
|
|
|
|
|
37
|
|
|
$files = $finder->files() |
|
38
|
|
|
->name("*.yml") |
|
39
|
|
|
->in(dirname($reflection->getFilename()) . '/Resources/config/ml-compose/'); |
|
40
|
|
|
|
|
41
|
|
|
foreach ($files as $file) { |
|
42
|
|
|
$config = Yaml::parse(file_get_contents($file)); |
|
43
|
|
|
$container->prependExtensionConfig('e_xpansion_ml_compose', $config['ml_compose']); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Loads a specific configuration. |
|
50
|
|
|
* |
|
51
|
|
|
* @param array $configs An array of configuration values |
|
52
|
|
|
* @param ContainerBuilder $container A ContainerBuilder instance |
|
53
|
|
|
* |
|
54
|
|
|
* @throws \InvalidArgumentException When provided tag is not defined in this extension |
|
55
|
|
|
*/ |
|
56
|
|
|
public function load(array $configs, ContainerBuilder $container) |
|
57
|
|
|
{ |
|
58
|
|
|
$expressionLanguage = new ExpressionLanguage(); |
|
59
|
|
|
$configuration = new Configuration(); |
|
60
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
|
61
|
|
|
|
|
62
|
|
|
foreach ($config as $key => $definition) { |
|
63
|
|
|
if (isset($definition['config'])) { |
|
64
|
|
|
foreach ($definition['config'] as $configKey => $value) { |
|
65
|
|
|
$config[$key]['config'][$configKey] = $expressionLanguage->compile($value); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
$container->getDefinition(BlockDefinition::class) |
|
71
|
|
|
->setArgument("", function () use ($config) { return $config['ml_compose']; }); |
|
72
|
|
|
} |
|
73
|
|
|
} |