|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: olive |
|
5
|
|
|
* Date: 12/03/2017 |
|
6
|
|
|
* Time: 10:04 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace eXpansion\Framework\Core\DependencyInjection; |
|
10
|
|
|
|
|
11
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
12
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
|
13
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
14
|
|
|
use Symfony\Component\Config\FileLocator; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
|
16
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
17
|
|
|
|
|
18
|
|
|
class eXpansionCoreExtension extends Extension implements PrependExtensionInterface |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
public function prepend(ContainerBuilder $container) |
|
22
|
|
|
{ |
|
23
|
|
|
$bundles = $container->getParameter('kernel.bundles'); |
|
24
|
|
|
|
|
25
|
|
|
foreach ($bundles as $bundle) { |
|
26
|
|
|
$reflection = new \ReflectionClass($bundle); |
|
27
|
|
|
|
|
28
|
|
View Code Duplication |
if (is_file($file = dirname($reflection->getFilename()) . '/Resources/config/expansion_defaults/core_config.yml')) { |
|
|
|
|
|
|
29
|
|
|
$config = Yaml::parse(file_get_contents(realpath($file))); |
|
30
|
|
|
$container->prependExtensionConfig('e_xpansion_core', $config['e_xpansion_core']); |
|
31
|
|
|
} |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
View Code Duplication |
if (is_file($file = $container->getParameter('kernel.root_dir') . '/config/expansion.yml')) { |
|
|
|
|
|
|
35
|
|
|
$config = Yaml::parse(file_get_contents(realpath($file))); |
|
36
|
|
|
$container->prependExtensionConfig('e_xpansion_core', $config['e_xpansion_core']); |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Loads a specific configuration. |
|
42
|
|
|
* |
|
43
|
|
|
* @param array $configs An array of configuration values |
|
44
|
|
|
* @param ContainerBuilder $container A ContainerBuilder instance |
|
45
|
|
|
* |
|
46
|
|
|
* @throws \InvalidArgumentException When provided tag is not defined in this extension |
|
47
|
|
|
*/ |
|
48
|
|
|
public function load(array $configs, ContainerBuilder $container) |
|
49
|
|
|
{ |
|
50
|
|
|
$configuration = new Configuration(); |
|
51
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
|
52
|
|
|
$container->setParameter("expansion.core.widget_positions", $config['widget_positions']); |
|
53
|
|
|
|
|
54
|
|
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
55
|
|
|
$loader->load('commands.yml'); |
|
56
|
|
|
$loader->load('services.yml'); |
|
57
|
|
|
$loader->load('data_providers.yml'); |
|
58
|
|
|
$loader->load('storage.yml'); |
|
59
|
|
|
$loader->load('user_groups.yml'); |
|
60
|
|
|
$loader->load('ml_scripts.yml'); |
|
61
|
|
|
$loader->load('gui.yml'); |
|
62
|
|
|
$loader->load('gui_grid.yml'); |
|
63
|
|
|
$loader->load('helpers.yml'); |
|
64
|
|
|
$loader->load('listeners.yml'); |
|
65
|
|
|
$loader->load('configs.yml'); |
|
66
|
|
|
|
|
67
|
|
|
// Temporary for the prototype. |
|
68
|
|
|
$loader->load('plugins.yml'); |
|
69
|
|
|
|
|
70
|
|
|
if ($container->getParameter('kernel.environment') == 'dev') { |
|
71
|
|
|
$loader->load('plugins_dev.yml'); |
|
72
|
|
|
} elseif ($container->getParameter('kernel.environment') == 'prod') { |
|
73
|
|
|
$loader->load('plugins_prod.yml'); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.