diff options
author | ArthurHoaro <arthur@hoa.ro> | 2018-07-28 11:07:55 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2018-07-28 11:07:55 +0200 |
commit | 83faedadff76c5bdca036f39f13943f63b27e164 (patch) | |
tree | 6f44cede16ec6a60f10b9699e211e0818f06d2c8 /application/config/ConfigJson.php | |
parent | 1d9eb22a3df85b67fe6652c0876cd7382c2fb525 (diff) | |
parent | 658988f3aeba7a5a938783249ccf2765251e5597 (diff) | |
download | Shaarli-83faedadff76c5bdca036f39f13943f63b27e164.tar.gz Shaarli-83faedadff76c5bdca036f39f13943f63b27e164.tar.zst Shaarli-83faedadff76c5bdca036f39f13943f63b27e164.zip |
Merge tag 'v0.9.7' into stable
Release v0.9.7
Diffstat (limited to 'application/config/ConfigJson.php')
-rw-r--r-- | application/config/ConfigJson.php | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/application/config/ConfigJson.php b/application/config/ConfigJson.php index 30007eb4..8c8d5610 100644 --- a/application/config/ConfigJson.php +++ b/application/config/ConfigJson.php | |||
@@ -1,4 +1,5 @@ | |||
1 | <?php | 1 | <?php |
2 | namespace Shaarli\Config; | ||
2 | 3 | ||
3 | /** | 4 | /** |
4 | * Class ConfigJson (ConfigIO implementation) | 5 | * Class ConfigJson (ConfigIO implementation) |
@@ -10,7 +11,7 @@ class ConfigJson implements ConfigIO | |||
10 | /** | 11 | /** |
11 | * @inheritdoc | 12 | * @inheritdoc |
12 | */ | 13 | */ |
13 | function read($filepath) | 14 | public function read($filepath) |
14 | { | 15 | { |
15 | if (! is_readable($filepath)) { | 16 | if (! is_readable($filepath)) { |
16 | return array(); | 17 | return array(); |
@@ -20,8 +21,19 @@ class ConfigJson implements ConfigIO | |||
20 | $data = str_replace(self::getPhpSuffix(), '', $data); | 21 | $data = str_replace(self::getPhpSuffix(), '', $data); |
21 | $data = json_decode($data, true); | 22 | $data = json_decode($data, true); |
22 | if ($data === null) { | 23 | if ($data === null) { |
23 | $error = json_last_error(); | 24 | $errorCode = json_last_error(); |
24 | throw new Exception('An error occurred while parsing JSON file: error code #'. $error); | 25 | $error = sprintf( |
26 | 'An error occurred while parsing JSON configuration file (%s): error code #%d', | ||
27 | $filepath, | ||
28 | $errorCode | ||
29 | ); | ||
30 | $error .= '<br>➜ <code>' . json_last_error_msg() .'</code>'; | ||
31 | if ($errorCode === JSON_ERROR_SYNTAX) { | ||
32 | $error .= '<br>'; | ||
33 | $error .= 'Please check your JSON syntax (without PHP comment tags) using a JSON lint tool such as '; | ||
34 | $error .= '<a href="http://jsonlint.com/">jsonlint.com</a>.'; | ||
35 | } | ||
36 | throw new \Exception($error); | ||
25 | } | 37 | } |
26 | return $data; | 38 | return $data; |
27 | } | 39 | } |
@@ -29,16 +41,16 @@ class ConfigJson implements ConfigIO | |||
29 | /** | 41 | /** |
30 | * @inheritdoc | 42 | * @inheritdoc |
31 | */ | 43 | */ |
32 | function write($filepath, $conf) | 44 | public function write($filepath, $conf) |
33 | { | 45 | { |
34 | // JSON_PRETTY_PRINT is available from PHP 5.4. | 46 | // JSON_PRETTY_PRINT is available from PHP 5.4. |
35 | $print = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0; | 47 | $print = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0; |
36 | $data = self::getPhpHeaders() . json_encode($conf, $print) . self::getPhpSuffix(); | 48 | $data = self::getPhpHeaders() . json_encode($conf, $print) . self::getPhpSuffix(); |
37 | if (!file_put_contents($filepath, $data)) { | 49 | if (!file_put_contents($filepath, $data)) { |
38 | throw new IOException( | 50 | throw new \IOException( |
39 | $filepath, | 51 | $filepath, |
40 | 'Shaarli could not create the config file. | 52 | t('Shaarli could not create the config file. '. |
41 | Please make sure Shaarli has the right to write in the folder is it installed in.' | 53 | 'Please make sure Shaarli has the right to write in the folder is it installed in.') |
42 | ); | 54 | ); |
43 | } | 55 | } |
44 | } | 56 | } |
@@ -46,7 +58,7 @@ class ConfigJson implements ConfigIO | |||
46 | /** | 58 | /** |
47 | * @inheritdoc | 59 | * @inheritdoc |
48 | */ | 60 | */ |
49 | function getExtension() | 61 | public function getExtension() |
50 | { | 62 | { |
51 | return '.json.php'; | 63 | return '.json.php'; |
52 | } | 64 | } |