1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class Ajde_Config_Repository extends Ajde_Object_Standard |
4
|
|
|
{ |
5
|
|
|
/** |
6
|
|
|
* TODO |
7
|
|
|
* |
8
|
|
|
* @param string $directory |
9
|
|
|
*/ |
10
|
|
|
public function __construct($directory) |
11
|
|
|
{ |
12
|
|
|
$this->readConfigDir($directory); |
13
|
|
|
$this->defaults(); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* TODO |
18
|
|
|
* |
19
|
|
|
* @param string $directory |
20
|
|
|
*/ |
21
|
|
|
public function readConfigDir($directory) |
22
|
|
|
{ |
23
|
|
|
$environment = Environment::current(); |
24
|
|
|
|
25
|
|
|
$searchDirs = [ |
26
|
|
|
CORE_DIR . $directory, '*.json', |
27
|
|
|
CORE_DIR . $directory . $environment . DS, '*.json', |
28
|
|
|
APP_DIR . $directory, '*.json', |
29
|
|
|
APP_DIR . $directory . $environment . DS, '*.json' |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
foreach($searchDirs as $searchDir) { |
33
|
|
|
foreach(Ajde_Fs_Find::findFiles($searchDir, '*.json') as $configFile) |
34
|
|
|
{ |
35
|
|
|
$this->merge(pathinfo($configFile, PATHINFO_FILENAME), json_decode(file_get_contents($configFile), true)); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function defaults() |
41
|
|
|
{ |
42
|
|
|
// URI fragments |
43
|
|
|
$this->site_protocol = (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS'])) ? 'https://' : 'http://'; |
|
|
|
|
44
|
|
|
$this->site_domain = $_SERVER['SERVER_NAME']; |
|
|
|
|
45
|
|
|
$this->site_path = str_replace('index.php', '', $_SERVER['PHP_SELF']); |
|
|
|
|
46
|
|
|
|
47
|
|
|
// Assembled URI |
48
|
|
|
$this->site_root = $this->site_protocol . $this->site_domain . $this->site_path; |
|
|
|
|
49
|
|
|
|
50
|
|
|
// Assembled URI with language identifier |
51
|
|
|
$this->lang_root = $this->site_root; |
|
|
|
|
52
|
|
|
|
53
|
|
|
// Set default timezone now |
54
|
|
|
date_default_timezone_set($this->timezone); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: