APPDIR.'config/'.$name.'.php', 'options' => array() ); else static::load_group($name, $file); } return static::$groups[$name]['options']; } /** * Loads group from file * * @param string $name Name to assign the loaded group * @param string $file File to load * @access public * @static */ public static function load_group($name, $file) { static::$groups[$name] = array( 'file' => $file, 'options' => include($file) ); } /** * Retrieves a configuration value. You can use a dot notation * to access properties in group arrays. The first part of the key * specifies the configuration file from which options should be loaded from * * //Loads ['default']['user'] option * //from database.php configuration file * Config::get('database.default.user'); * * * @param string $key Configuration key to retrieve. * @param string $default Default value to return if the key is not found. * @return mixed Configuration value * @access public * @throws Exception If default value is not specified and the key is not found * @static */ public static function get() { $p = func_get_args(); $keys = explode('.', $p[0]); $group_name = array_shift($keys); $group = static::get_group($group_name); if (empty($keys)) return $group; $total = count($keys); foreach ($keys as $i => $key) { if (isset($group[$key])) { if ($i == $total - 1) return $group[$key]; $group = &$group[$key]; }else { if (array_key_exists(1, $p)) return $p[1]; throw new Exception("Configuration not set for {$p[0]}."); } } } /** * Sets a configuration option. * * @param string $key Configuration key to set * @param string $value Value to set for this option * @access public * @static */ public static function set($key, $value) { $keys = explode('.', $key); $group_name = array_shift($keys); $group = static::get_group($group_name); $subgroup = &$group; $last_key = count($keys) - 1; foreach ($keys as $i => $key) { if ($i == $last_key) { $subgroup[$key] = $value; } else { if (!isset($subgroup[$key]) || !is_array($subgroup[$key])) $subgroup[$key] = array(); $subgroup = & $subgroup[$key]; } } static::$groups[$group_name]['options'] = $group; } /** * Writes a configuration group back to the file it was loaded from * * @param string $group Name of the group to write * @access public * @static */ public static function write($group) { static::get_group($group); $group = static::$groups[$group]; file_put_contents($group['file'], "