1 | <?php |
||
10 | class Config |
||
11 | { |
||
12 | /** |
||
13 | * @var string $configDirName Directory's name in config dir |
||
14 | */ |
||
15 | protected $configDirName = ''; |
||
16 | |||
17 | /** |
||
18 | * @var string $configDir Complete path of the readed directory |
||
19 | */ |
||
20 | protected $configDir = ''; |
||
21 | |||
22 | /** |
||
23 | * @var string[] $configFiles List of files to read |
||
24 | */ |
||
25 | protected $configFiles = []; |
||
26 | |||
27 | /** |
||
28 | * @var array $config List of config value found |
||
29 | */ |
||
30 | protected $config = []; |
||
31 | |||
32 | /** |
||
33 | * Constructor |
||
34 | * Define properties configDirName and configDir |
||
35 | * |
||
36 | * @param string $configDirName Directory's name in config dir |
||
37 | */ |
||
38 | public function __construct($configDirName) |
||
43 | |||
44 | /** |
||
45 | * Getter accessor to $config property |
||
46 | * |
||
47 | * @return array |
||
48 | */ |
||
49 | public function getConfig() |
||
53 | |||
54 | /** |
||
55 | * Getter accessor to a value into the $config property |
||
56 | * |
||
57 | * @param type $file |
||
58 | * |
||
59 | * @return type |
||
60 | */ |
||
61 | public function getConfigForFile($file) |
||
65 | |||
66 | /** |
||
67 | * Search and load all config files which has been found |
||
68 | * |
||
69 | * @return void |
||
70 | */ |
||
71 | public function loadFiles() |
||
79 | |||
80 | /** |
||
81 | * Search all config files in a directory |
||
82 | * Search also in sub-directory (2nd parameter) |
||
83 | * |
||
84 | * @param string $dirPath The directory path where is run the search |
||
85 | * @param string $pathIntoFirstDir (default '') Used when this method |
||
86 | * reads a subdirectory. It's the path of the readed directory during |
||
87 | * the first call to this method. |
||
88 | * |
||
89 | * @return void |
||
90 | */ |
||
91 | protected function searchAllConfigFiles($dirPath, $pathIntoFirstDir = '') |
||
116 | |||
117 | /** |
||
118 | * Load a config file. |
||
119 | * Find the file's extension and call the method to parse the file |
||
120 | * |
||
121 | * @param string $fileKey The file's key. Most of the time, the path to |
||
122 | * the file from the $this->configDir value |
||
123 | * @param string $filePath The path to the file |
||
124 | * |
||
125 | * @return void |
||
126 | */ |
||
127 | protected function loadConfigFile($fileKey, $filePath) |
||
143 | |||
144 | /** |
||
145 | * Load a json config file |
||
146 | * |
||
147 | * @param string $fileKey The file's key. Most of the time, the path to |
||
148 | * the file from the $this->configDir value |
||
149 | * @param string $filePath The path to the file |
||
150 | * |
||
151 | * @return void |
||
152 | * |
||
153 | * @throws Exception If there is an error from the json parser |
||
154 | */ |
||
155 | protected function loadJsonConfigFile($fileKey, $filePath) |
||
166 | |||
167 | /** |
||
168 | * Load a php config file |
||
169 | * |
||
170 | * @param string $fileKey The file's key. Most of the time, the path to |
||
171 | * the file from the $this->configDir value |
||
172 | * @param string $filePath The path to the file |
||
173 | * |
||
174 | * @return void |
||
175 | */ |
||
176 | protected function loadPhpConfigFile($fileKey, $filePath) |
||
180 | |||
181 | /** |
||
182 | * Return a config value for a key |
||
183 | * |
||
184 | * @param string $key The asked key for the value |
||
185 | * @param string $file (default null) If many file is loaded, the file name |
||
186 | * where is the key. Is the file is into a sub-directory, the |
||
187 | * sub-directory should be present. |
||
188 | * |
||
189 | * @return mixed |
||
190 | * |
||
191 | * @throws Exception If file parameter is null and there are many files. Or |
||
192 | * if the file not exist. Or if the key not exist. |
||
193 | */ |
||
194 | public function getValue($key, $file = null) |
||
222 | } |
||
223 |