-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigLoader.php
More file actions
76 lines (62 loc) · 1.8 KB
/
ConfigLoader.php
File metadata and controls
76 lines (62 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace Wcoppens\Phalcon\ConfigLoader;
use Phalcon\Config\Adapter\ExtendedYaml;
use Phalcon\Config\Exception;
/**
* Class ConfigLoader
*
* Default loader for Phalcon project inspired by the Yaml file loading system used in Symfony2.
*/
class ConfigLoader extends ExtendedYaml {
/**
* @var array
*/
public $parameters = [];
/**
* @param string $configDir
* @param string $appRoot
* @param string $env
* @throws Exception
*/
public function __construct($configDir, $appRoot, $env = 'prod') {
$parametersYaml = new ExtendedYaml($configDir . '/parameters.yml');
$this->parameters = $parametersYaml->parameters;
//Store app_root temporary in parameters
$this->parameters['app_root'] = $appRoot;
parent::__construct($configDir . '/config.yml', $this->subscribedCallbacks());
parent::merge(new ExtendedYaml($configDir . '/config_' . $env . '.yml', $this->subscribedCallbacks()));
}
/**
* Method which returns the callbacks for the ExtendedYaml instance.
*
* @return array
*/
private function subscribedCallbacks() {
return [
'!parameter' => function($key) {
return $this->parameter($key);
},
'!approot' => function($value) {
return $this->appRoot($value);
}
];
}
/**
* Method returning the parameter value for the given key
*
* @param $key
* @return mixed
*/
private function parameter($key) {
return $this->parameters->{$key};
}
/**
* Method returning full path for given value
*
* @param $value
* @return string
*/
private function appRoot($value) {
return $this->parameters->app_root . $value;
}
}