* @copyright 2017-2021 The CMSimple_XH developers * @copyright GNU GPLv3 * @since 1.7.0 */ class PluginConfig implements ArrayAccess { /** * Whether this is a language configuration. * * @var bool */ private $language; /** * The loaded plugin configurations. * * @var array */ private $configs = array(); /** * Initializes a new instance. * * @param bool $language Whether this is a language configuration. */ public function __construct($language = false) { $this->language = $language; } /** * Returns whether an offset exists. * * @param mixed $offset An offset. * * @return bool */ #[\ReturnTypeWillChange] public function offsetExists($offset) { if (!isset($this->configs[$offset])) { $this->loadConfig($offset); } return isset($this->configs[$offset]); } /** * Returns the value at an offset. * * @param mixed $offset An offset. * * @return array */ #[\ReturnTypeWillChange] public function offsetGet($offset) { if (!isset($this->configs[$offset])) { $this->loadConfig($offset); } return $this->configs[$offset]; } /** * Sets the value at an offset. * * @param mixed $offset An offset. * @param mixed $value A value. * * @return void */ #[\ReturnTypeWillChange] public function offsetSet($offset, $value) { if (!isset($this->configs[$offset])) { $this->loadConfig($offset); } $this->configs[$offset] = $value; } /** * Unsets an offset. * * @param mixed $offset An offset. * * @return void */ #[\ReturnTypeWillChange] public function offsetUnset($offset) { if (!isset($this->configs[$offset])) { $this->loadConfig($offset); } unset($this->configs[$offset]); } /** * Loads the configuration. * * @param string $pluginname A plugin name. * * @return void */ private function loadConfig($pluginname) { global $pth; pluginFiles($pluginname); if ($this->language) { XH_createLanguageFile($pth['file']['plugin_language']); } $this->configs += XH_readConfiguration(true, $this->language); } }