aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/config/ConfigPhp.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/config/ConfigPhp.php')
-rw-r--r--application/config/ConfigPhp.php22
1 files changed, 12 insertions, 10 deletions
diff --git a/application/config/ConfigPhp.php b/application/config/ConfigPhp.php
index 27187b66..8add8bcd 100644
--- a/application/config/ConfigPhp.php
+++ b/application/config/ConfigPhp.php
@@ -1,4 +1,5 @@
1<?php 1<?php
2namespace Shaarli\Config;
2 3
3/** 4/**
4 * Class ConfigPhp (ConfigIO implementation) 5 * Class ConfigPhp (ConfigIO implementation)
@@ -41,6 +42,7 @@ class ConfigPhp implements ConfigIO
41 'resource.log' => 'config.LOG_FILE', 42 'resource.log' => 'config.LOG_FILE',
42 'resource.update_check' => 'config.UPDATECHECK_FILENAME', 43 'resource.update_check' => 'config.UPDATECHECK_FILENAME',
43 'resource.raintpl_tpl' => 'config.RAINTPL_TPL', 44 'resource.raintpl_tpl' => 'config.RAINTPL_TPL',
45 'resource.theme' => 'config.theme',
44 'resource.raintpl_tmp' => 'config.RAINTPL_TMP', 46 'resource.raintpl_tmp' => 'config.RAINTPL_TMP',
45 'resource.thumbnails_cache' => 'config.CACHEDIR', 47 'resource.thumbnails_cache' => 'config.CACHEDIR',
46 'resource.page_cache' => 'config.PAGECACHE', 48 'resource.page_cache' => 'config.PAGECACHE',
@@ -71,7 +73,7 @@ class ConfigPhp implements ConfigIO
71 /** 73 /**
72 * @inheritdoc 74 * @inheritdoc
73 */ 75 */
74 function read($filepath) 76 public function read($filepath)
75 { 77 {
76 if (! file_exists($filepath) || ! is_readable($filepath)) { 78 if (! file_exists($filepath) || ! is_readable($filepath)) {
77 return array(); 79 return array();
@@ -81,17 +83,17 @@ class ConfigPhp implements ConfigIO
81 83
82 $out = array(); 84 $out = array();
83 foreach (self::$ROOT_KEYS as $key) { 85 foreach (self::$ROOT_KEYS as $key) {
84 $out[$key] = $GLOBALS[$key]; 86 $out[$key] = isset($GLOBALS[$key]) ? $GLOBALS[$key] : '';
85 } 87 }
86 $out['config'] = $GLOBALS['config']; 88 $out['config'] = isset($GLOBALS['config']) ? $GLOBALS['config'] : [];
87 $out['plugins'] = !empty($GLOBALS['plugins']) ? $GLOBALS['plugins'] : array(); 89 $out['plugins'] = isset($GLOBALS['plugins']) ? $GLOBALS['plugins'] : [];
88 return $out; 90 return $out;
89 } 91 }
90 92
91 /** 93 /**
92 * @inheritdoc 94 * @inheritdoc
93 */ 95 */
94 function write($filepath, $conf) 96 public function write($filepath, $conf)
95 { 97 {
96 $configStr = '<?php '. PHP_EOL; 98 $configStr = '<?php '. PHP_EOL;
97 foreach (self::$ROOT_KEYS as $key) { 99 foreach (self::$ROOT_KEYS as $key) {
@@ -99,7 +101,7 @@ class ConfigPhp implements ConfigIO
99 $configStr .= '$GLOBALS[\'' . $key . '\'] = ' . var_export($conf[$key], true) . ';' . PHP_EOL; 101 $configStr .= '$GLOBALS[\'' . $key . '\'] = ' . var_export($conf[$key], true) . ';' . PHP_EOL;
100 } 102 }
101 } 103 }
102 104
103 // Store all $conf['config'] 105 // Store all $conf['config']
104 foreach ($conf['config'] as $key => $value) { 106 foreach ($conf['config'] as $key => $value) {
105 $configStr .= '$GLOBALS[\'config\'][\''. $key .'\'] = '.var_export($conf['config'][$key], true).';'. PHP_EOL; 107 $configStr .= '$GLOBALS[\'config\'][\''. $key .'\'] = '.var_export($conf['config'][$key], true).';'. PHP_EOL;
@@ -114,10 +116,10 @@ class ConfigPhp implements ConfigIO
114 if (!file_put_contents($filepath, $configStr) 116 if (!file_put_contents($filepath, $configStr)
115 || strcmp(file_get_contents($filepath), $configStr) != 0 117 || strcmp(file_get_contents($filepath), $configStr) != 0
116 ) { 118 ) {
117 throw new IOException( 119 throw new \IOException(
118 $filepath, 120 $filepath,
119 'Shaarli could not create the config file. 121 t('Shaarli could not create the config file. '.
120 Please make sure Shaarli has the right to write in the folder is it installed in.' 122 'Please make sure Shaarli has the right to write in the folder is it installed in.')
121 ); 123 );
122 } 124 }
123 } 125 }
@@ -125,7 +127,7 @@ class ConfigPhp implements ConfigIO
125 /** 127 /**
126 * @inheritdoc 128 * @inheritdoc
127 */ 129 */
128 function getExtension() 130 public function getExtension()
129 { 131 {
130 return '.php'; 132 return '.php';
131 } 133 }