|
@@ -92,7 +92,7 @@ class JsonFile
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
- file_put_contents($this->path, $this->encode($hash, $prettyPrint));
|
|
|
+ file_put_contents($this->path, static::encode($hash, $prettyPrint));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -105,7 +105,7 @@ class JsonFile
|
|
|
* @param Boolean $prettyPrint If true, output is pretty-printed
|
|
|
* @return string Indented version of the original JSON string
|
|
|
*/
|
|
|
- public function encode(array $hash, $prettyPrint = true)
|
|
|
+ static public function encode(array $hash, $prettyPrint = true)
|
|
|
{
|
|
|
if ($prettyPrint && defined('JSON_PRETTY_PRINT')) {
|
|
|
return json_encode($hash, JSON_PRETTY_PRINT);
|
|
@@ -181,7 +181,7 @@ class JsonFile
|
|
|
*
|
|
|
* @return array
|
|
|
*/
|
|
|
- public static function parseJson($json)
|
|
|
+ static public function parseJson($json)
|
|
|
{
|
|
|
$data = json_decode($json, true);
|
|
|
|
|
@@ -206,7 +206,7 @@ class JsonFile
|
|
|
$msg .= ', extra comma';
|
|
|
} elseif (preg_match('#((?<=[^\\\\])\\\\(?!["\\\\/bfnrt]|u[a-f0-9]{4}))#i', $json, $match, PREG_OFFSET_CAPTURE)) {
|
|
|
$msg .= ', unescaped backslash (\\)';
|
|
|
- } elseif (preg_match('#(["}\]]) *\r?\n *"#', $json, $match, PREG_OFFSET_CAPTURE)) {
|
|
|
+ } elseif (preg_match('#(["}\]])(?: *\r?\n *)+"#', $json, $match, PREG_OFFSET_CAPTURE)) {
|
|
|
$msg .= ', missing comma';
|
|
|
$charOffset = 1;
|
|
|
} elseif (preg_match('#^ *([a-z0-9_-]+) *:#mi', $json, $match, PREG_OFFSET_CAPTURE)) {
|
|
@@ -215,6 +215,8 @@ class JsonFile
|
|
|
$msg .= ', use double quotes (") instead of single quotes (\')';
|
|
|
} elseif (preg_match('#(\[".*?":.*?\])#', $json, $match, PREG_OFFSET_CAPTURE)) {
|
|
|
$msg .= ', you must use the hash syntax (e.g. {"foo": "bar"}) instead of array syntax (e.g. ["foo", "bar"])';
|
|
|
+ } elseif (preg_match('#".*?"( *["{\[])#', $json, $match, PREG_OFFSET_CAPTURE)) {
|
|
|
+ $msg .= ', missing colon';
|
|
|
}
|
|
|
if (isset($match[1][1])) {
|
|
|
$preError = substr($json, 0, $match[1][1]);
|