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 {