forked from APIJet/APIJet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.php
More file actions
36 lines (27 loc) · 863 Bytes
/
Config.php
File metadata and controls
36 lines (27 loc) · 863 Bytes
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
<?php
namespace APIJet;
class Config
{
private $configStore = [];
public function get($name)
{
return $this->configStore[$name];
}
public function set(array $newConfig)
{
$this->configStore = $newConfig + $this->configStore;
}
public function loadByJsonFile($filepath)
{
$fileContent = file_get_contents($filepath);
if ($fileContent == false) {
trigger_error("Cannot read configuration file at ".$filepath, E_USER_ERROR);
}
$newConfig = json_decode($fileContent, true);
$lastJsonError = json_last_error();
if ($lastJsonError !== JSON_ERROR_NONE) {
trigger_error("Occured while parsing json, ".json_last_error_msg(), E_USER_ERROR);
}
$this->set($newConfig);
}
}