Skip to content

Commit dbb6014

Browse files
committed
Fix call to \json_decode() in Config::loadJson()
1 parent 7f4ce19 commit dbb6014

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/Libraries/Core/Config.php

+5-9
Original file line numberDiff line numberDiff line change
@@ -100,27 +100,23 @@ protected static function getValueByKey(string $key, array $haystack, mixed $def
100100
* Reads the JSON configuration file from disk into application memory.
101101
*
102102
* @return boolean Whether the operation was successful.
103+
* @throws UnexpectedValueException when the JSON configuration file is unavailable.
103104
*/
104105
public static function loadJson(): bool
105106
{
106107
self::$json_config = null;
107108

108109
if (!\file_exists(self::JSON_CONFIG_PATH) || !\is_readable(self::JSON_CONFIG_PATH))
109110
{
110-
return false;
111+
throw new \UnexpectedValueException('Cannot retrieve application JSON configuration');
111112
}
112113

113114
$buffer = \file_get_contents(self::JSON_CONFIG_PATH);
114-
if ($buffer === false)
115-
{
116-
throw new \UnexpectedValueException('Cannot retrieve application JSON configuration');
117-
}
118-
self::$json_config = \json_decode($buffer, true, self::JSON_FLAGS);
119-
$json_errno = \json_last_error();
120-
if ($json_errno != \JSON_ERROR_NONE)
115+
if ($buffer === false || empty($buffer))
121116
{
122-
throw new \JsonException(\json_last_error_msg(), $json_errno);
117+
throw new \UnexpectedValueException('Application JSON configuration is empty');
123118
}
119+
self::$json_config = \json_decode($buffer, true, 512, self::JSON_FLAGS);
124120

125121
return true;
126122
}

0 commit comments

Comments
 (0)