* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net) */ class ConfigORM extends ConfigORMAbstract { /** * The current filename. * * @var string filename */ private string $file; /** * Load the ConfigORM file. * * @param string $file * @return ConfigORM * @throws ConfigException */ public function load(string $file = ''): ConfigORM { if (empty($file)) { throw new ConfigException('Could not load config file. No file provided', 1); } elseif (file_exists($file)) { $this->file = $file; $this->cfg = (array) include $file; $this->originalCfg = $this->cfg; } else { throw new ConfigException('Could not load config file. Config file does not exist', 1); } return $this; } /** * Updates the config file and writes it. * * @throws ConfigException on fatal error */ public function commit(): bool { // If config has a lock file, don't write if (isset($this->cfg['lock'])) throw new ConfigException("Could not write config file. $this->file is locked with the 'lock' key."); // Write the changes if (is_writable($this->file)) { $config = var_export($this->cfg, true); file_put_contents($this->file, "file is not writable", 1); } }