aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/config
diff options
context:
space:
mode:
Diffstat (limited to 'application/config')
-rw-r--r--application/config/ConfigManager.php84
1 files changed, 41 insertions, 43 deletions
diff --git a/application/config/ConfigManager.php b/application/config/ConfigManager.php
index c0482cf3..5aafc89d 100644
--- a/application/config/ConfigManager.php
+++ b/application/config/ConfigManager.php
@@ -2,13 +2,13 @@
2 2
3// FIXME! Namespaces... 3// FIXME! Namespaces...
4require_once 'ConfigIO.php'; 4require_once 'ConfigIO.php';
5require_once 'ConfigPhp.php';
6require_once 'ConfigJson.php'; 5require_once 'ConfigJson.php';
6require_once 'ConfigPhp.php';
7 7
8/** 8/**
9 * Class ConfigManager 9 * Class ConfigManager
10 * 10 *
11 * Singleton, manages all Shaarli's settings. 11 * Manages all Shaarli's settings.
12 * See the documentation for more information on settings: 12 * See the documentation for more information on settings:
13 * - doc/Shaarli-configuration.html 13 * - doc/Shaarli-configuration.html
14 * - https://github.com/shaarli/Shaarli/wiki/Shaarli-configuration 14 * - https://github.com/shaarli/Shaarli/wiki/Shaarli-configuration
@@ -16,19 +16,14 @@ require_once 'ConfigJson.php';
16class ConfigManager 16class ConfigManager
17{ 17{
18 /** 18 /**
19 * @var ConfigManager instance. 19 * @var string Flag telling a setting is not found.
20 */ 20 */
21 protected static $instance = null; 21 protected static $NOT_FOUND = 'NOT_FOUND';
22 22
23 /** 23 /**
24 * @var string Config folder. 24 * @var string Config folder.
25 */ 25 */
26 public static $CONFIG_FILE = 'data/config'; 26 protected $configFile;
27
28 /**
29 * @var string Flag telling a setting is not found.
30 */
31 protected static $NOT_FOUND = 'NOT_FOUND';
32 27
33 /** 28 /**
34 * @var array Loaded config array. 29 * @var array Loaded config array.
@@ -41,37 +36,20 @@ class ConfigManager
41 protected $configIO; 36 protected $configIO;
42 37
43 /** 38 /**
44 * Private constructor: new instances not allowed. 39 * Constructor.
45 */ 40 */
46 private function __construct() {} 41 public function __construct($configFile = 'data/config')
47
48 /**
49 * Cloning isn't allowed either.
50 */
51 private function __clone() {}
52
53 /**
54 * Return existing instance of PluginManager, or create it.
55 *
56 * @return ConfigManager instance.
57 */
58 public static function getInstance()
59 { 42 {
60 if (!(self::$instance instanceof self)) { 43 $this->configFile = $configFile;
61 self::$instance = new self(); 44 $this->initialize();
62 self::$instance->initialize();
63 }
64
65 return self::$instance;
66 } 45 }
67 46
68 /** 47 /**
69 * Reset the ConfigManager instance. 48 * Reset the ConfigManager instance.
70 */ 49 */
71 public static function reset() 50 public function reset()
72 { 51 {
73 self::$instance = null; 52 $this->initialize();
74 return self::getInstance();
75 } 53 }
76 54
77 /** 55 /**
@@ -87,10 +65,10 @@ class ConfigManager
87 */ 65 */
88 protected function initialize() 66 protected function initialize()
89 { 67 {
90 if (! file_exists(self::$CONFIG_FILE .'.php')) { 68 if (file_exists($this->configFile . '.php')) {
91 $this->configIO = new ConfigJson();
92 } else {
93 $this->configIO = new ConfigPhp(); 69 $this->configIO = new ConfigPhp();
70 } else {
71 $this->configIO = new ConfigJson();
94 } 72 }
95 $this->load(); 73 $this->load();
96 } 74 }
@@ -100,7 +78,7 @@ class ConfigManager
100 */ 78 */
101 protected function load() 79 protected function load()
102 { 80 {
103 $this->loadedConfig = $this->configIO->read($this->getConfigFile()); 81 $this->loadedConfig = $this->configIO->read($this->getConfigFileExt());
104 $this->setDefaultValues(); 82 $this->setDefaultValues();
105 } 83 }
106 84
@@ -213,7 +191,7 @@ class ConfigManager
213 ); 191 );
214 192
215 // Only logged in user can alter config. 193 // Only logged in user can alter config.
216 if (is_file(self::$CONFIG_FILE) && !$isLoggedIn) { 194 if (is_file($this->getConfigFileExt()) && !$isLoggedIn) {
217 throw new UnauthorizedConfigException(); 195 throw new UnauthorizedConfigException();
218 } 196 }
219 197
@@ -224,17 +202,37 @@ class ConfigManager
224 } 202 }
225 } 203 }
226 204
227 return $this->configIO->write($this->getConfigFile(), $this->loadedConfig); 205 return $this->configIO->write($this->getConfigFileExt(), $this->loadedConfig);
228 } 206 }
229 207
230 /** 208 /**
231 * Get the configuration file path. 209 * Set the config file path (without extension).
232 * 210 *
233 * @return string Config file path. 211 * @param string $configFile File path.
212 */
213 public function setConfigFile($configFile)
214 {
215 $this->configFile = $configFile;
216 }
217
218 /**
219 * Return the configuration file path (without extension).
220 *
221 * @return string Config path.
234 */ 222 */
235 public function getConfigFile() 223 public function getConfigFile()
236 { 224 {
237 return self::$CONFIG_FILE . $this->configIO->getExtension(); 225 return $this->configFile;
226 }
227
228 /**
229 * Get the configuration file path with its extension.
230 *
231 * @return string Config file path.
232 */
233 public function getConfigFileExt()
234 {
235 return $this->configFile . $this->configIO->getExtension();
238 } 236 }
239 237
240 /** 238 /**
@@ -302,7 +300,7 @@ class ConfigManager
302 $this->setEmpty('path.page_cache', 'pagecache'); 300 $this->setEmpty('path.page_cache', 'pagecache');
303 301
304 $this->setEmpty('security.ban_after', 4); 302 $this->setEmpty('security.ban_after', 4);
305 $this->setEmpty('security.ban_after', 1800); 303 $this->setEmpty('security.ban_duration', 1800);
306 $this->setEmpty('security.session_protection_disabled', false); 304 $this->setEmpty('security.session_protection_disabled', false);
307 305
308 $this->setEmpty('general.check_updates', false); 306 $this->setEmpty('general.check_updates', false);