]>
git.immae.eu Git - github/shaarli/Shaarli.git/blob - application/config/ConfigPhp.php
4 * Class ConfigPhp (ConfigIO implementation)
6 * Handle Shaarli's legacy PHP configuration file.
7 * Note: this is only designed to support the transition to JSON configuration.
9 class ConfigPhp
implements ConfigIO
12 * @var array List of config key without group.
14 public static $ROOT_KEYS = array(
22 'disablesessionprotection',
23 'privateLinkByDefault',
29 function read($filepath)
31 if (! file_exists($filepath) || ! is_readable($filepath)) {
38 foreach (self
::$ROOT_KEYS as $key) {
39 $out[$key] = $GLOBALS[$key];
41 $out['config'] = $GLOBALS['config'];
42 $out['plugins'] = !empty($GLOBALS['plugins']) ? $GLOBALS['plugins'] : array();
49 function write($filepath, $conf)
51 $configStr = '<?php '. PHP_EOL
;
52 foreach (self
::$ROOT_KEYS as $key) {
53 if (isset($conf[$key])) {
54 $configStr .= '$GLOBALS[\'' . $key . '\'] = ' . var_export($conf[$key], true) . ';' . PHP_EOL
;
58 // Store all $conf['config']
59 foreach ($conf['config'] as $key => $value) {
60 $configStr .= '$GLOBALS[\'config\'][\''. $key .'\'] = '.var_export($conf['config'][$key], true).';'. PHP_EOL
;
63 if (isset($conf['plugins'])) {
64 foreach ($conf['plugins'] as $key => $value) {
65 $configStr .= '$GLOBALS[\'plugins\'][\''. $key .'\'] = '.var_export($conf['plugins'][$key], true).';'. PHP_EOL
;
70 //$configStr .= 'date_default_timezone_set('.var_export($conf['timezone'], true).');'. PHP_EOL;
72 if (!file_put_contents($filepath, $configStr)
73 || strcmp(file_get_contents($filepath), $configStr) != 0
75 throw new IOException(
77 'Shaarli could not create the config file.
78 Please make sure Shaarli has the right to write in the folder is it installed in.'
86 function getExtension()