This commit is contained in:
Fred Tempez 2023-03-02 21:07:25 +01:00
parent 63b17453dd
commit 00a1f57665
1 changed files with 19 additions and 13 deletions

View File

@ -52,7 +52,8 @@ class JsonDb extends \Prowebcraft\Dot
public function set($key, $value = null, $save = true)
{
parent::set($key, $value);
if ($save) $this->save();
if ($save)
$this->save();
return $this;
}
@ -68,7 +69,8 @@ class JsonDb extends \Prowebcraft\Dot
public function add($key, $value = null, $pop = false, $save = true)
{
parent::add($key, $value, $pop);
if ($save) $this->save();
if ($save)
$this->save();
return $this;
}
@ -82,7 +84,8 @@ class JsonDb extends \Prowebcraft\Dot
public function delete($key, $save = true)
{
parent::delete($key);
if ($save) $this->save();
if ($save)
$this->save();
return $this;
}
@ -98,7 +101,8 @@ class JsonDb extends \Prowebcraft\Dot
public function clear($key = null, $format = false, $save = true)
{
parent::clear($key, $format);
if ($save) $this->save();
if ($save)
$this->save();
return $this;
}
@ -108,7 +112,8 @@ class JsonDb extends \Prowebcraft\Dot
* @param bool $reload Reboot data?
* @return array|mixed|null
*/
protected function loadData($reload = false) {
protected function loadData($reload = false)
{
if ($this->data === null || $reload) {
$this->db = $this->config['dir'] . DIRECTORY_SEPARATOR . $this->config['name'];
if (!file_exists($this->db)) {
@ -135,7 +140,8 @@ class JsonDb extends \Prowebcraft\Dot
/**
* Save database
*/
public function save() {
public function save()
{
$lenght = strlen(json_encode($this->data));
$try = 0;
while ($try < 5) {