_parent_instance = $instance; $this->_group_name = $group; parent::__construct($config, ArrayObject::ARRAY_AS_PROPS); } /** * Return the current group in serialized form. * * echo $config; * * @return string */ public function __toString() { return serialize($this->getArrayCopy()); } /** * Alias for getArrayCopy() * * @return array Array copy of the group's config */ public function as_array() { return $this->getArrayCopy(); } /** * Returns the config group's name * * @return string The group name */ public function group_name() { return $this->_group_name; } /** * Get a variable from the configuration or return the default value. * * $value = $config->get($key); * * @param string $key array key * @param mixed $default default value * @return mixed */ public function get($key, $default = NULL) { return $this->offsetExists($key) ? $this->offsetGet($key) : $default; } /** * Sets a value in the configuration array. * * $config->set($key, $new_value); * * @param string $key array key * @param mixed $value array value * @return $this */ public function set($key, $value) { $this->offsetSet($key, $value); return $this; } /** * Overrides ArrayObject::offsetSet() * This method is called when config is changed via * * $config->var = 'asd'; * * // OR * * $config['var'] = 'asd'; * * @param string $key The key of the config item we're changing * @param mixed $value The new array value */ #[\ReturnTypeWillChange] public function offsetSet($key, $value) { $this->_parent_instance->_write_config($this->_group_name, $key, $value); return parent::offsetSet($key, $value); } }