public static function load() { if (!file_exists(self::$datafolder)) { mkdir(self::$datafolder, 0777); } $datafolder = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, self::$datafolder); $files = ['config.json']; foreach ($files as $file) { if (!file_exists($datafolder . $file)) { self::getLogger()->info("The " . $file . " is not found"); $baseconfig = ["loginProtection" => ["loginTimeout" => 5]]; file_put_contents($datafolder . $file, json_encode($baseconfig, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); self::getLogger()->info("The " . $file . " was created"); } self::getLogger()->info("Loading " . $file); self::$config[str_replace(".json", "", $file)] = json_decode(file_get_contents($datafolder . $file), true); Utils::getJsonErrors(); self::getLogger()->info($file . " is loaded"); } }
/** * Save the users into the file * @return bool */ public static function save() { file_put_contents(Config::getDataFolder() . "users.json", json_encode(self::$users, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); if (!Utils::getJsonErrors()) { Config::getLogger()->info("Users saved !"); } else { Config::getLogger()->error("An error occured while saving users !"); } return Utils::getJsonErrors(); }