From d89d8cdf8d841a5b29e6ab1464437271fbe12375 Mon Sep 17 00:00:00 2001 From: slawkens Date: Sat, 6 Jun 2020 07:55:26 +0200 Subject: [PATCH] Add Settings Class --- system/libs/Settings.php | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 system/libs/Settings.php diff --git a/system/libs/Settings.php b/system/libs/Settings.php new file mode 100644 index 00000000..51e1098f --- /dev/null +++ b/system/libs/Settings.php @@ -0,0 +1,44 @@ + + * @copyright 2020 MyAAC + * @link https://my-aac.org + */ + +class Settings implements ArrayAccess +{ + private $container = array(); + + public function offsetSet($offset, $value) { + if (is_null($offset)) { + $this->container[] = $value; + } else { + $this->container[$offset] = $value; + } + } + + public function offsetExists($offset) { + return isset($this->container[$offset]); + } + + public function offsetUnset($offset) { + unset($this->container[$offset]); + } + + public function offsetGet($offset) + { + if (!isset($this->container[$offset])) { + $file = PLUGINS . $offset . '/settings.php'; + if(!file_exists($file)) { + throw new \RuntimeException('Failed to load settings file for plugin: ' . $offset); + } + + $this->container[$offset] = require $file; + } + + return $this->container[$offset]; + } +} \ No newline at end of file