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.autoreload', // 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 | 'angular.protection', // Add an angular suggested prefix in order to avoid JSONP injections |
||
59 | 'cors.headers', // Add extra headers to the CORS check |
||
60 | 'json.encodeUTF8', // Encode the json response |
||
61 | 'cache.data.enable', // Enable data caching with PSFS |
||
62 | ]; |
||
63 | protected $debug = false; |
||
64 | |||
65 | /** |
||
66 | * Method that load the configuration data into the system |
||
67 | * @return Config |
||
68 | */ |
||
69 | 1 | protected function init() |
|
76 | |||
77 | /** |
||
78 | * @return bool |
||
79 | */ |
||
80 | 1 | public function isLoaded() { |
|
83 | |||
84 | /** |
||
85 | * Method that saves the configuration |
||
86 | * @param array $data |
||
87 | * @param array $extra |
||
88 | * @return array |
||
89 | */ |
||
90 | 3 | protected static function saveConfigParams(array $data, array $extra) |
|
104 | |||
105 | /** |
||
106 | * Method that saves the extra parameters into the configuration |
||
107 | * @param array $data |
||
108 | * @return array |
||
109 | */ |
||
110 | 3 | protected static function saveExtraParams(array $data) |
|
123 | |||
124 | /** |
||
125 | * Method that returns if the system is in debug mode |
||
126 | * @return boolean |
||
127 | */ |
||
128 | 7 | public function getDebugMode() |
|
132 | |||
133 | /** |
||
134 | * @param bool $debug |
||
135 | */ |
||
136 | 1 | public function setDebugMode($debug = true) { |
|
140 | |||
141 | /** |
||
142 | * Method that checks if the platform is proper configured |
||
143 | * @return boolean |
||
144 | */ |
||
145 | 2 | public function isConfigured() |
|
159 | |||
160 | /** |
||
161 | * Method that check if the user is trying to save the config |
||
162 | * @return bool |
||
163 | */ |
||
164 | 2 | public function checkTryToSaveConfig() |
|
170 | |||
171 | /** |
||
172 | * Method that saves all the configuration in the system |
||
173 | * |
||
174 | * @param array $data |
||
175 | * @param array|null $extra |
||
176 | * @return boolean |
||
177 | */ |
||
178 | 3 | public static function save(array $data, array $extra = null) |
|
195 | |||
196 | /** |
||
197 | * Method that returns a config value |
||
198 | * @param string $param |
||
199 | * @param mixed $defaultValue |
||
200 | * |
||
201 | * @return mixed|null |
||
202 | */ |
||
203 | 20 | public function get($param, $defaultValue = null) |
|
207 | |||
208 | /** |
||
209 | * Method that returns all the configuration |
||
210 | * @return array |
||
211 | */ |
||
212 | 2 | public function dumpConfig() |
|
216 | |||
217 | /** |
||
218 | * Method that reloads config file |
||
219 | */ |
||
220 | 3 | public function loadConfigData() |
|
225 | |||
226 | /** |
||
227 | * Clear configuration set |
||
228 | */ |
||
229 | 1 | public function clearConfig() |
|
233 | |||
234 | /** |
||
235 | * Static wrapper for extracting params |
||
236 | * @param string $key |
||
237 | * @param mixed|null $defaultValue |
||
238 | * @return mixed|null |
||
239 | */ |
||
240 | 20 | public static function getParam($key, $defaultValue = null) |
|
245 | } |
||
246 |
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.