1 | <?php |
||
13 | class Config |
||
14 | { |
||
15 | use SingletonTrait; |
||
16 | |||
17 | const DEFAULT_LANGUAGE = "es"; |
||
18 | const DEFAULT_ENCODE = "UTF-8"; |
||
19 | const DEFAULT_CTYPE = "text/html"; |
||
20 | const DEFAULT_DATETIMEZONE = "Europe/Madrid"; |
||
21 | |||
22 | const CONFIG_FILE = 'config.json'; |
||
23 | |||
24 | protected $config = array(); |
||
25 | static public $defaults = array( |
||
26 | "db_host" => "localhost", |
||
27 | "db_port" => "3306", |
||
28 | "default_language" => "es_ES", |
||
29 | "debug" => true, |
||
30 | "front.version" => "v1", |
||
31 | "version" => "v1", |
||
32 | ); |
||
33 | static public $required = array('db_host', 'db_port', 'db_name', 'db_user', 'db_password', 'home_action', 'default_language', 'debug'); |
||
|
|||
34 | static public $encrypted = array('db_password'); |
||
35 | static public $optional = [ |
||
36 | 'platform_name', // Platform name |
||
37 | 'restricted', // Restrict the web access |
||
38 | 'admin_login', // Enable web login for admin |
||
39 | 'logger.phpFire', // Enable phpFire to trace the logs in the browser |
||
40 | 'logger.memory', // Enable log memory usage un traces |
||
41 | 'poweredBy', // Show PoweredBy header customized |
||
42 | 'author', // Author for auto generated files |
||
43 | 'author_email', // Author email for auto generated files |
||
44 | 'version', // Platform version(for cache purposes) |
||
45 | 'front.version', // Static resources version |
||
46 | 'cors.enabled', // Enable CORS (regex with the domains, * for all) |
||
47 | 'pagination.limit', // Pagination limit for autogenerated api admin |
||
48 | 'api.secret', // Secret passphrase to securize the api |
||
49 | 'api.admin', // Enable de autogenerated api admin(wok) |
||
50 | 'log.level', // Max log level(default INFO) |
||
51 | 'admin_action', // Default admin url when access to /admin |
||
52 | 'cache.var', // Static cache var |
||
53 | 'twig.auto_reload', // Enable or disable auto reload templates for twig |
||
54 | 'modules.extend', // Variable for extending the current functionality |
||
55 | 'psfs.auth', // Variable for extending PSFS with the AUTH module |
||
56 | 'errors.strict', // Variable to trace all strict errors |
||
57 | 'psfs.memcache', // Add Memcache to prod cache process, ONLY for PROD environments |
||
58 | ]; |
||
59 | protected $debug = false; |
||
60 | |||
61 | /** |
||
62 | * Config Constructor |
||
63 | */ |
||
64 | public function __construct() |
||
68 | |||
69 | /** |
||
70 | * Method that load the configuration data into the system |
||
71 | * @return Config |
||
72 | */ |
||
73 | protected function init() |
||
80 | |||
81 | /** |
||
82 | * @return bool |
||
83 | */ |
||
84 | public function isLoaded() { |
||
87 | |||
88 | /** |
||
89 | * Method that saves the configuration |
||
90 | * @param array $data |
||
91 | * @param array $extra |
||
92 | * @return array |
||
93 | */ |
||
94 | 2 | protected static function saveConfigParams(array $data, array $extra) |
|
108 | |||
109 | /** |
||
110 | * Method that saves the extra parameters into the configuration |
||
111 | * @param array $data |
||
112 | * @return array |
||
113 | */ |
||
114 | 2 | protected static function saveExtraParams(array $data) |
|
127 | |||
128 | /** |
||
129 | * Method that returns if the system is in debug mode |
||
130 | * @return boolean |
||
131 | */ |
||
132 | 6 | public function getDebugMode() |
|
136 | |||
137 | /** |
||
138 | * Method that checks if the platform is proper configured |
||
139 | * @return boolean |
||
140 | */ |
||
141 | 2 | public function isConfigured() |
|
155 | |||
156 | /** |
||
157 | * Method that check if the user is trying to save the config |
||
158 | * @return bool |
||
159 | */ |
||
160 | 2 | public function checkTryToSaveConfig() |
|
166 | |||
167 | /** |
||
168 | * Method that saves all the configuration in the system |
||
169 | * |
||
170 | * @param array $data |
||
171 | * @param array|null $extra |
||
172 | * @return boolean |
||
173 | */ |
||
174 | 2 | public static function save(array $data, array $extra = null) |
|
191 | |||
192 | /** |
||
193 | * Method that returns a config value |
||
194 | * @param string $param |
||
195 | * @param mixed $defaultValue |
||
196 | * |
||
197 | * @return mixed|null |
||
198 | */ |
||
199 | 5 | public function get($param, $defaultValue = null) |
|
203 | |||
204 | /** |
||
205 | * Method that returns all the configuration |
||
206 | * @return array |
||
207 | */ |
||
208 | 2 | public function dumpConfig() |
|
212 | |||
213 | /** |
||
214 | * Method that reloads config file |
||
215 | */ |
||
216 | 2 | public function loadConfigData() |
|
221 | |||
222 | /** |
||
223 | * Clear configuration set |
||
224 | */ |
||
225 | 1 | public function clearConfig() |
|
229 | |||
230 | /** |
||
231 | * Static wrapper for extracting params |
||
232 | * @param string $key |
||
233 | * @param mixed|null $defaultValue |
||
234 | * @return mixed|null |
||
235 | */ |
||
236 | 4 | public static function getParam($key, $defaultValue = null) |
|
241 | } |
||
242 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.