|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* todo: make it cleaner: https://symfony.com/doc/current/bundles/prepend_extension.html. |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace PiedWeb\CMSBundle\DependencyInjection; |
|
7
|
|
|
|
|
8
|
|
|
use Symfony\Component\Config\FileLocator; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\Extension\Extension; |
|
11
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
|
12
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
|
13
|
|
|
use Symfony\Component\Finder\Finder; |
|
14
|
|
|
use Symfony\Component\Yaml\Parser; |
|
15
|
|
|
|
|
16
|
|
|
class PiedWebCMSExtension extends Extension implements PrependExtensionInterface |
|
17
|
|
|
{ |
|
18
|
|
|
public function load(array $configs, ContainerBuilder $container) |
|
19
|
|
|
{ |
|
20
|
|
|
$configuration = new Configuration(); //$configuration = $this->getConfiguration($configs, $container); |
|
21
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
|
22
|
|
|
|
|
23
|
|
|
self::loadConfigToParameters($container, $config); |
|
24
|
|
|
|
|
25
|
|
|
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
26
|
|
|
$loader->load('services.yaml'); |
|
27
|
|
|
|
|
28
|
|
|
// todo : https://symfony.com/doc/current/bundles/extension.html#adding-classes-to-compile |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param string $prefix must contain the last |
|
33
|
|
|
* |
|
34
|
|
|
* @return void |
|
35
|
|
|
*/ |
|
36
|
|
|
protected static function loadConfigToParameters(ContainerBuilder $container, array $config, $prefix = '') |
|
37
|
|
|
{ |
|
38
|
|
|
$container->setParameter('pwc', $config); |
|
39
|
|
|
|
|
40
|
|
|
foreach ($config as $key => $value) { |
|
41
|
|
|
if ('apps' === $key) { |
|
42
|
|
|
$container->setParameter('pwc.apps', self::parsAppsConfig($value)); |
|
43
|
|
|
} elseif (\is_array($value)) { |
|
44
|
|
|
self::loadConfigToParameters($container, $value, $prefix.$key.'.'); |
|
45
|
|
|
} else { |
|
46
|
|
|
$container->setParameter('app.'.$prefix.$key, $value); // to deprecate in next release |
|
47
|
|
|
$container->setParameter('pwc.'.$prefix.$key, $value); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
protected static function parsAppsConfig($apps) |
|
53
|
|
|
{ |
|
54
|
|
|
$result = []; |
|
55
|
|
|
foreach ($apps as $app) { |
|
56
|
|
|
$result[$app['hosts'][0]] = $app; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return $result; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function getAlias() |
|
63
|
|
|
{ |
|
64
|
|
|
return 'piedweb_cms'; // change to pwc todo |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function prepend(ContainerBuilder $container) |
|
68
|
|
|
{ |
|
69
|
|
|
// Load configurations for other package |
|
70
|
|
|
$parser = new Parser(); |
|
71
|
|
|
$finder = Finder::create()->files()->name('*.yaml')->in(__DIR__.'/../Resources/config/packages/'); |
|
72
|
|
|
foreach ($finder as $file) { |
|
73
|
|
|
$configs = $parser->parse(file_get_contents($file->getRealPath())); |
|
74
|
|
|
if ('sonata_admin_blob' == substr($file->getRealPath(), 0, -5)) { |
|
75
|
|
|
// check if extension is loaded |
|
76
|
|
|
} |
|
77
|
|
|
foreach ($configs as $name => $config) { |
|
78
|
|
|
if ( |
|
79
|
|
|
'piedweb_cms' == $name |
|
80
|
|
|
//|| 'security' == $name |
|
81
|
|
|
) { // this file is just for doc purpose |
|
82
|
|
|
continue; |
|
83
|
|
|
} |
|
84
|
|
|
$container->prependExtensionConfig($name, $config); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|