/** * ArrayAccess; Assigns a value to the specified offset. * * @param string $key * @param Config_File|array $value */ public function offsetSet($key, $value) { if (is_scalar($value) || is_resource($value)) { throw new Exception("Unable to set '{$key}' to '{$value}' for Config_Dir '{$this->_path}': Creating a section requires setting an array or Config_File object"); } if ($value instanceof Config_File) { $config = $value; if (isset($config->_path)) { throw new Exception("Unable to set '{$key}' to Config_File object for Config_Dir '{$this->_path}': Config_File path is already set'"); } if (isset($config->_ext) && isset($this->_ext) && $config->_ext != $this->_ext) { throw new Exception("Unable to create section '{$key}': Extension specified for Config_Dir '{$this->_path}' and extension specified for Config_File object setting are different"); } if (!isset($config->_ext) && !isset($this->_ext)) { throw new Exception("Unable to create section '{$key}': No extension specified for Config_Dir '{$this->_path}' or for the Config_File object setting"); } if (!isset($config->_ext)) { $config->_ext = $this->_ext; } if (isset($this->_transformer)) { $config->_transformer = $this->_transformer; } $config->_path = $config instanceof Config_Dir ? $this->_path->dir($key) : $this->_path->file("{$key}.{$this->_ext}"); } else { if (!$this->_ext) { throw new Exception("Unable to create section '{$key}': No extension specified for Config_Dir '{$this->_path}', creating a section requires setting a Config_File object"); } $options = array(); if ($this->_transformer) { $options['transformer'] = $this->_transformer; } $config = new Config_File(array($this->_path->file("{$key}.{$this->_ext}")), $options); $config->exchangeArray((array) $value); } parent::offsetSet($key, $config); }