1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package: chapi |
4
|
|
|
* |
5
|
|
|
* @author: msiebeneicher |
6
|
|
|
* @since: 2017-03-20 |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Chapi\Component\DependencyInjection\Loader; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
use Chapi\Component\Config\ChapiConfigInterface; |
14
|
|
|
use \InvalidArgumentException; |
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
16
|
|
|
|
17
|
|
|
class ChapiConfigLoader implements ChapiConfigLoaderInterface |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var ContainerBuilder |
21
|
|
|
*/ |
22
|
|
|
private $oContainer; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var ChapiConfigInterface |
26
|
|
|
*/ |
27
|
|
|
private $oConfig; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* ChapiConfigLoader constructor. |
31
|
|
|
* @param ContainerBuilder $oContainer |
32
|
|
|
* @param ChapiConfigInterface $oConfig |
33
|
|
|
*/ |
34
|
3 |
|
public function __construct(ContainerBuilder $oContainer, ChapiConfigInterface $oConfig) |
35
|
|
|
{ |
36
|
3 |
|
$this->oContainer = $oContainer; |
37
|
3 |
|
$this->oConfig = $oConfig; |
38
|
3 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @inheritdoc |
42
|
|
|
*/ |
43
|
3 |
|
public function loadProfileParameters() |
44
|
|
|
{ |
45
|
3 |
|
$_aContent = $this->oConfig->getProfileConfig(); |
46
|
|
|
|
47
|
3 |
|
$this->oContainer->addObjectResource($this->oConfig); |
48
|
|
|
|
49
|
|
|
// empty config |
50
|
3 |
|
if (empty($_aContent)) { |
51
|
1 |
|
return; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
// parameters |
55
|
2 |
|
if (isset($_aContent['parameters'])) { |
56
|
2 |
|
$this->validate($_aContent); |
57
|
1 |
|
$this->setParameters($_aContent['parameters']); |
58
|
|
|
} |
59
|
1 |
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param array $aContent |
63
|
|
|
* @throws InvalidArgumentException |
64
|
|
|
* @return void |
65
|
|
|
*/ |
66
|
2 |
|
private function validate(array &$aContent) |
67
|
|
|
{ |
68
|
2 |
|
if (isset($aContent['parameters']) && !is_array($aContent['parameters'])) { |
69
|
1 |
|
throw new InvalidArgumentException('The "parameters" key should contain an array. Please check your configuration files.'); |
70
|
|
|
} |
71
|
1 |
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param array $aParameters |
75
|
|
|
*/ |
76
|
1 |
|
private function setParameters(array &$aParameters) |
77
|
|
|
{ |
78
|
1 |
|
foreach ($aParameters as $key => $value) { |
79
|
1 |
|
$this->oContainer->setParameter($key, $value); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
} |