From 14683133c85e8e0074b2865e7e88213db2678132 Mon Sep 17 00:00:00 2001 From: fredtempez Date: Thu, 14 Mar 2024 19:14:06 +0100 Subject: [PATCH] =?UTF-8?q?Json=20v=C3=A9rif?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/class/jsondb/JsonDb.class.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/class/jsondb/JsonDb.class.php b/core/class/jsondb/JsonDb.class.php index f6f1f86..29d932a 100644 --- a/core/class/jsondb/JsonDb.class.php +++ b/core/class/jsondb/JsonDb.class.php @@ -130,8 +130,8 @@ class JsonDb extends \Prowebcraft\Dot } $this->data = json_decode(file_get_contents($this->db), true); if (!$this->data === null && json_last_error() !== JSON_ERROR_NONE) { - throw new \InvalidArgumentException('Database file ' . $this->db - . ' contains invalid json object. Please validate or remove file'); + throw new \InvalidArgumentException('Le fichier ' . $this->db + . ' contient des données invalides.'); } } return $this->data; @@ -146,6 +146,10 @@ class JsonDb extends \Prowebcraft\Dot // $v = json_encode($this->data, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT); $l = strlen($v); $t = 0; + if ($v === false) { + error_log('Erreur d\'encodage JSON : ' . json_last_error_msg()); + exit ('Erreur d\'encodage JSON : ' . json_last_error_msg()); + } while ($t < 5) { $w = file_put_contents($this->db, $v); // Multi user get a locker if ($w == $l) {