|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Akeneo\Bundle\MeasureBundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Config\FileLocator; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
|
8
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
9
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Load measure bundle configuration from any bundles |
|
13
|
|
|
* |
|
14
|
|
|
* @author Nicolas Dupont <[email protected]> |
|
15
|
|
|
* @copyright 2012 Akeneo SAS (http://www.akeneo.com) |
|
16
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
|
17
|
|
|
*/ |
|
18
|
|
|
class AkeneoMeasureExtension extends Extension |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* {@inheritDoc} |
|
22
|
|
|
*/ |
|
23
|
|
|
public function load(array $configs, ContainerBuilder $container) |
|
24
|
|
|
{ |
|
25
|
|
|
// retrieve each measure config from bundles |
|
26
|
|
|
$measuresConfig = []; |
|
27
|
|
|
foreach ($container->getParameter('kernel.bundles') as $bundle) { |
|
28
|
|
|
$reflection = new \ReflectionClass($bundle); |
|
29
|
|
|
if (is_file($file = dirname($reflection->getFilename()).'/Resources/config/measure.yml')) { |
|
30
|
|
|
// merge measures configs |
|
31
|
|
|
if (empty($measuresConfig)) { |
|
32
|
|
|
$measuresConfig = Yaml::parse(file_get_contents(realpath($file))); |
|
33
|
|
|
} else { |
|
34
|
|
|
$entities = Yaml::parse(file_get_contents(realpath($file))); |
|
35
|
|
|
foreach ($entities['measures_config'] as $family => $familyConfig) { |
|
36
|
|
|
// merge result with already existing family config to add custom units |
|
37
|
|
|
if (isset($measuresConfig['measures_config'][$family])) { |
|
38
|
|
|
$measuresConfig['measures_config'][$family]['units'] = |
|
39
|
|
|
array_merge( |
|
40
|
|
|
$measuresConfig['measures_config'][$family]['units'], |
|
41
|
|
|
$familyConfig['units'] |
|
42
|
|
|
); |
|
43
|
|
|
} else { |
|
44
|
|
|
$measuresConfig['measures_config'][$family] = $familyConfig; |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
$configs[] = $measuresConfig; |
|
51
|
|
|
// process configurations to validate and merge |
|
52
|
|
|
$configuration = new Configuration(); |
|
53
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
|
54
|
|
|
|
|
55
|
|
|
// load service |
|
56
|
|
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
57
|
|
|
$loader->load('services.yml'); |
|
58
|
|
|
// set measures config |
|
59
|
|
|
$container->setParameter('akeneo_measure.measures_config', $config); |
|
60
|
|
|
|
|
61
|
|
|
$container |
|
62
|
|
|
->getDefinition('akeneo_measure.manager') |
|
63
|
|
|
->addMethodCall('setMeasureConfig', $config); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|