import_file($import_file); } public function importFile(string $file): self { if(!file_exists($file)) throw new Conf\Exception("fileMissing"); if(!is_readable($file)) throw new Conf\Exception("fileUnreadable"); $json = @file_get_contents($file); if($json===false) throw new Conf\Exception("fileUnreadable"); return $this->import($json); } public function import(string $json): self { if($json=="") throw new Conf\Exception("blank"); $json = json_decode($json, true); if(!is_array($json)) throw new Conf\Exception("corrupt"); foreach($json as $key => $value) { $this->$$key = $value; } return $this; } public function export(string $file = ""): string { return json_encode($this, JSON_PRETTY_PRINT); } public function __toString(): string { return $this->export(); } }