* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net) */ abstract class ConfigORMAbstract implements Iterator { /** * The original state of a config file. Can be reverted to using revert(). * * @var array Config file */ protected $originalCfg = []; /** * The current state of a config file. * * @var array Config file */ protected $cfg = []; /** * Revert to the original conditions of the config file. */ public function revert() { $this->cfg = $this->originalCfg; } /** * Checks if a requested key is set in the config file. * * @param string $name Parameter name * * @return bool true on isset, false on not */ public function __isset($name) { return isset($this->cfg[$name]); } /** * Return a value from a config file. * * @param string $name Key of the requested entry * * @return mixed Value of the requested entry */ public function __get($name) { return $this->cfg[$name]; } /** * Sets an entry in the config file. * * @param string $name Key of the entry * @param mixed $value Value of the entry */ public function __set($name, $value) { $this->cfg[$name] = $value; } /** * Unset a value in a config file. * * @param string Key of the entry */ public function __unset($name) { unset($this->cfg[$name]); } /** * Iterator method. */ public function rewind() { return reset($this->cfg); } /** * Iterator method. */ public function current() { return current($this->cfg); } /** * Iterator method. */ public function key() { return key($this->cfg); } /** * Iterator method. */ public function next() { return next($this->cfg); } /** * Iterator method. */ public function valid() { return key($this->cfg) !== null; } /** * Returns the config file as an array. * * @return array Config file */ public function toArray() { return $this->cfg; } }