1 | <?php |
||
17 | class Config |
||
18 | { |
||
19 | use SingletonTrait; |
||
20 | const DEFAULT_LANGUAGE = "es"; |
||
21 | const DEFAULT_ENCODE = "UTF-8"; |
||
22 | const DEFAULT_CTYPE = "text/html"; |
||
23 | const DEFAULT_DATETIMEZONE = "Europe/Madrid"; |
||
24 | |||
25 | const CONFIG_FILE = 'config.json'; |
||
26 | |||
27 | protected $config = array(); |
||
28 | static public $defaults = array( |
||
29 | "db_host" => "localhost", |
||
30 | "db_port" => "3306", |
||
31 | "default_language" => "es_ES", |
||
32 | "debug" => true, |
||
33 | "front.version" => "v1", |
||
34 | "version" => "v1", |
||
35 | ); |
||
36 | static public $required = array('db_host', 'db_port', 'db_name', 'db_user', 'db_password', 'home_action', 'default_language', 'debug'); |
||
|
|||
37 | static public $encrypted = array('db_password'); |
||
38 | static public $optional = [ |
||
39 | 'platform_name', // Platform name |
||
40 | 'restricted', // Restrict the web access |
||
41 | 'admin_login', // Enable web login for admin |
||
42 | 'logger.phpFire', // Enable phpFire to trace the logs in the browser |
||
43 | 'logger.memory', // Enable log memory usage un traces |
||
44 | 'poweredBy', // Show PoweredBy header customized |
||
45 | 'author', // Author for auto generated files |
||
46 | 'author_email', // Author email for auto generated files |
||
47 | 'version', // Platform version(for cache purposes) |
||
48 | 'front.version', // Static resources version |
||
49 | 'cors.enabled', // Enable CORS (regex with the domains, * for all) |
||
50 | 'pagination.limit', // Pagination limit for autogenerated api admin |
||
51 | 'api.secret', // Secret passphrase to securize the api |
||
52 | 'api.admin', // Enable de autogenerated api admin(wok) |
||
53 | 'log.level', // Max log level(default INFO) |
||
54 | 'admin_action', // Default admin url when access to /admin |
||
55 | 'cache.var', // Static cache var |
||
56 | 'twig.auto_reload', // Enable or disable auto reload templates for twig |
||
57 | 'modules.extend', // Variable for extending the current functionality |
||
58 | ]; |
||
59 | protected $debug = false; |
||
60 | |||
61 | /** |
||
62 | * Config Constructor |
||
63 | */ |
||
64 | 8 | public function __construct() |
|
68 | |||
69 | /** |
||
70 | * Method that load the configuration data into the system |
||
71 | * @return Config |
||
72 | */ |
||
73 | 8 | protected function init() |
|
80 | |||
81 | /** |
||
82 | * Method that saves the configuration |
||
83 | * @param array $data |
||
84 | * @param array $extra |
||
85 | * @return array |
||
86 | */ |
||
87 | 2 | protected static function saveConfigParams(array $data, array $extra) |
|
101 | |||
102 | /** |
||
103 | * Method that saves the extra parameters into the configuration |
||
104 | * @param array $data |
||
105 | * @return array |
||
106 | */ |
||
107 | 2 | protected static function saveExtraParams(array $data) |
|
120 | |||
121 | /** |
||
122 | * Method that returns if the system is in debug mode |
||
123 | * @return boolean |
||
124 | */ |
||
125 | 6 | public function getDebugMode() |
|
129 | |||
130 | /** |
||
131 | * Method that checks if the platform is proper configured |
||
132 | * @return boolean |
||
133 | */ |
||
134 | 2 | public function isConfigured() |
|
148 | |||
149 | /** |
||
150 | * Method that check if the user is trying to save the config |
||
151 | * @return bool |
||
152 | */ |
||
153 | 2 | public function checkTryToSaveConfig() |
|
159 | |||
160 | /** |
||
161 | * Method that saves all the configuration in the system |
||
162 | * |
||
163 | * @param array $data |
||
164 | * @param array|null $extra |
||
165 | * @return boolean |
||
166 | */ |
||
167 | 2 | public static function save(array $data, array $extra = null) |
|
181 | |||
182 | /** |
||
183 | * Method that returns a config value |
||
184 | * @param string $param |
||
185 | * @param mixed $defaultValue |
||
186 | * |
||
187 | * @return mixed|null |
||
188 | */ |
||
189 | 4 | public function get($param, $defaultValue = null) |
|
193 | |||
194 | /** |
||
195 | * Method that returns all the configuration |
||
196 | * @return array |
||
197 | */ |
||
198 | 2 | public function dumpConfig() |
|
202 | |||
203 | /** |
||
204 | * Method that reloads config file |
||
205 | */ |
||
206 | 2 | public function loadConfigData() |
|
213 | |||
214 | /** |
||
215 | * Clear configuration set |
||
216 | */ |
||
217 | 1 | public function clearConfig() |
|
221 | |||
222 | /** |
||
223 | * Static wrapper for extracting params |
||
224 | * @param string $key |
||
225 | * @param mixed|null $defaultValue |
||
226 | * @return mixed|null |
||
227 | */ |
||
228 | 2 | public static function getParam($key, $defaultValue = null) { |
|
232 | } |
||
233 |
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.