* @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 array $originalCfg = []; /** * The current state of a config file. * * @var array Config file */ protected array $cfg = []; /** * Revert to the original conditions of the config file. */ public function revert() { $this->cfg = $this->originalCfg; } /** * Clears the current config */ public function clear() { $this->cfg = []; } /** * Replaces keys and values in the config with the provided array * * @param array $replacementArray */ public function replace(array $replacementArray) { foreach ($replacementArray as $key => $value) { $this->cfg[$key] = $value; } } /** * Checks if a requested key is set in the config file. * * @param string $name Parameter name * @return bool true on isset, false on not * @codeCoverageIgnore */ public function __isset(string $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 * @codeCoverageIgnore */ public function __get(string $name) { return $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 * @codeCoverageIgnore */ public function get(string $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 * @codeCoverageIgnore */ public function __set(string $name, $value) { $this->cfg[$name] = $value; } /** * Sets an entry in the config file. * * @param string $name Key of the entry * @param mixed $value Value of the entry * @codeCoverageIgnore */ public function set(string $name, $value) { $this->cfg[$name] = $value; } /** * Unset a value in a config file. * * @param string Key of the entry * @codeCoverageIgnore */ public function __unset($name) { unset($this->cfg[$name]); } /** * Iterator method. * @codeCoverageIgnore */ public function rewind() { return reset($this->cfg); } /** * Iterator method. * @codeCoverageIgnore */ public function current() { return current($this->cfg); } /** * Iterator method. * @codeCoverageIgnore */ public function key() { return key($this->cfg); } /** * Iterator method. * @codeCoverageIgnore */ public function next() { return next($this->cfg); } /** * Iterator method. * @codeCoverageIgnore */ public function valid(): bool { return key($this->cfg) !== null; } /** * Returns the config file as an array. * * @return array Config file */ public function toArray(): array { return $this->cfg; } }