|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package CleverStyle CMS |
|
4
|
|
|
* @author Nazar Mokrynskyi <[email protected]> |
|
5
|
|
|
* @copyright Copyright (c) 2011-2016, Nazar Mokrynskyi |
|
6
|
|
|
* @license MIT License, see license.txt |
|
7
|
|
|
*/ |
|
8
|
|
|
namespace cs; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Core class. |
|
12
|
|
|
* Provides loading of base system configuration |
|
13
|
|
|
* |
|
14
|
|
|
* @method static $this instance($check = false) |
|
15
|
|
|
* |
|
16
|
|
|
* @property string $domain |
|
17
|
|
|
* @property string $timezone |
|
18
|
|
|
* @property string $db_host |
|
19
|
|
|
* @property string $db_type |
|
20
|
|
|
* @property string $db_name |
|
21
|
|
|
* @property string $db_user |
|
22
|
|
|
* @property string $db_password |
|
23
|
|
|
* @property string $db_prefix |
|
24
|
|
|
* @property string $db_charset |
|
25
|
|
|
* @property string $storage_type |
|
26
|
|
|
* @property string $storage_url |
|
27
|
|
|
* @property string $storage_host |
|
28
|
|
|
* @property string $storage_user |
|
29
|
|
|
* @property string $storage_password |
|
30
|
|
|
* @property string $language |
|
31
|
|
|
* @property string $cache_engine |
|
32
|
|
|
* @property string $memcache_host |
|
33
|
|
|
* @property string $memcache_port |
|
34
|
|
|
* @property string $public_key |
|
35
|
|
|
*/ |
|
36
|
|
|
class Core { |
|
37
|
|
|
use Singleton; |
|
38
|
|
|
/** |
|
39
|
|
|
* Is object constructed |
|
40
|
|
|
* @var bool |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $constructed = false; |
|
43
|
|
|
/** |
|
44
|
|
|
* @var mixed[] |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $config = []; |
|
47
|
|
|
/** |
|
48
|
|
|
* Loading of base system configuration, creating of missing directories |
|
49
|
|
|
*/ |
|
50
|
|
|
protected function construct () { |
|
51
|
|
|
$this->config = $this->load_config(); |
|
52
|
|
|
include_once DIR.'/config/main.php'; |
|
53
|
|
|
$this->constructed = true; |
|
54
|
|
|
} |
|
55
|
|
|
/** |
|
56
|
|
|
* Load main.json config file and return array of it contents |
|
57
|
|
|
* |
|
58
|
|
|
* @return array |
|
59
|
|
|
*/ |
|
60
|
|
|
protected function load_config () { |
|
61
|
|
|
if (!file_exists(DIR.'/config/main.json')) { |
|
62
|
|
|
if (PHP_SAPI == 'cli') { |
|
63
|
|
|
echo <<<CONFIG_NOT_FOUND |
|
64
|
|
|
Config file not found, is system installed properly? |
|
65
|
|
|
How to install CleverStyle CMS: https://github.com/nazar-pc/CleverStyle-CMS/wiki/Installation |
|
66
|
|
|
|
|
67
|
|
|
CONFIG_NOT_FOUND; |
|
68
|
|
|
} else { |
|
69
|
|
|
echo /** @lang HTML */ |
|
70
|
|
|
<<<CONFIG_NOT_FOUND |
|
71
|
|
|
<!doctype html> |
|
72
|
|
|
<p>Config file not found, is system installed properly?</p> |
|
73
|
|
|
<a href="https://github.com/nazar-pc/CleverStyle-CMS/wiki/Installation">How to install CleverStyle CMS</a> |
|
74
|
|
|
CONFIG_NOT_FOUND; |
|
75
|
|
|
http_response_code(500); |
|
76
|
|
|
} |
|
77
|
|
|
// Can't proceed without config |
|
78
|
|
|
exit(500); |
|
79
|
|
|
} |
|
80
|
|
|
return file_get_json_nocomments(DIR.'/config/main.json'); |
|
81
|
|
|
} |
|
82
|
|
|
/** |
|
83
|
|
|
* Getting of base configuration parameter |
|
84
|
|
|
* |
|
85
|
|
|
* @param string $item |
|
86
|
|
|
* |
|
87
|
|
|
* @return false|string |
|
88
|
|
|
*/ |
|
89
|
|
|
function get ($item) { |
|
90
|
|
|
return isset($this->config[$item]) ? $this->config[$item] : false; |
|
91
|
|
|
} |
|
92
|
|
|
/** |
|
93
|
|
|
* Setting of base configuration parameter (available only at object construction) |
|
94
|
|
|
* |
|
95
|
|
|
* @param string $item |
|
96
|
|
|
* @param mixed $value |
|
97
|
|
|
*/ |
|
98
|
|
|
function set ($item, $value) { |
|
99
|
|
|
if (!$this->constructed) { |
|
100
|
|
|
$this->config[$item] = $value; |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
/** |
|
104
|
|
|
* Getting of base configuration parameter |
|
105
|
|
|
* |
|
106
|
|
|
* @param string $item |
|
107
|
|
|
* |
|
108
|
|
|
* @return false|string |
|
109
|
|
|
*/ |
|
110
|
|
|
function __get ($item) { |
|
111
|
|
|
return $this->get($item); |
|
112
|
|
|
} |
|
113
|
|
|
/** |
|
114
|
|
|
* Setting of base configuration parameter (available only at object construction) |
|
115
|
|
|
* |
|
116
|
|
|
* @param string $item |
|
117
|
|
|
* @param mixed $value |
|
118
|
|
|
*/ |
|
119
|
|
|
function __set ($item, $value) { |
|
120
|
|
|
$this->set($item, $value); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|