From 8321ec244f6a93937590de8626f2cb529962128c Mon Sep 17 00:00:00 2001 From: "origami11@yandex.ru" Date: Thu, 16 Feb 2023 16:18:29 +0300 Subject: [PATCH] =?UTF-8?q?fix=20=D0=9D=D0=B5=20=D0=B7=D0=B0=D0=BF=D0=B8?= =?UTF-8?q?=D1=81=D1=8B=D0=B2=D0=B0=D1=82=D1=8C=20=D1=84=D0=B0=D0=B9=D0=BB?= =?UTF-8?q?=20=D0=B5=D1=81=D0=BB=D0=B8=20=D0=BE=D0=BD=20=D0=BD=D0=B5=D0=B1?= =?UTF-8?q?=D1=8B=D0=BB=20=D0=BF=D1=80=D0=BE=D1=87=D1=82=D0=B5=D0=BD,=20?= =?UTF-8?q?=D0=B8=D0=BD=D0=B0=D1=87=D0=B5=20=D0=BC=D0=BE=D0=B6=D0=B5=D0=BC?= =?UTF-8?q?=20=D0=BF=D0=BE=D1=82=D0=B5=D1=80=D1=8F=D1=82=D1=8C=20=D0=B4?= =?UTF-8?q?=D0=B0=D0=BD=D0=BD=D1=8B=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Settings.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Settings.php b/src/Settings.php index 69afd15..8345c1c 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -18,6 +18,7 @@ class Settings public $data = []; protected $file; protected $format = 'php'; + protected $is_read = false; public function __construct ($file = null, $format = false) { @@ -35,6 +36,7 @@ class Settings public function read() { if (!file_exists ($this->file)) { + $this->is_read = true; return false; } // Не include_once т.к читать настройки можно несколько раз @@ -49,6 +51,7 @@ class Settings throw new Exception('no data in ' . $this->file); } + $this->is_read = true; $this->data = $settings; return true; } @@ -165,6 +168,10 @@ class Settings */ public function write($file = null) { + if (!$this->is_read) { + throw new Exception('read settings before write'); + } + if ($this->format == 'json') { $result = json_encode($this->data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); } else {