From 57922c5a4d89e25f88190bfa2fa835035c2a33a2 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 14 Aug 2011 14:08:04 -0500 Subject: [PATCH] allow Config::set to set an entire configuation array. --- system/config.php | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/system/config.php b/system/config.php index c6b75ad0..ac91f5b5 100644 --- a/system/config.php +++ b/system/config.php @@ -5,12 +5,14 @@ class Config { /** * All of the loaded configuration items. * + * The configuration item arrays are keyed by module and file. + * * @var array */ public static $items = array(); /** - * Determine if a configuration item or file exists. + * Determine if a configuration file or item exists. * * @param string $key * @return bool @@ -30,6 +32,14 @@ class Config { * If the name of a configuration file is passed without specifying an item, the * entire configuration array will be returned. * + * + * // Get the application timezone + * $timezone = Config::get('application.timezone'); + * + * // Get the application configuration array + * $application = Config::get('application'); + * + * * @param string $key * @param string $default * @return array @@ -51,6 +61,16 @@ class Config { /** * Set a configuration item. * + * If a configuration item is not specified, the entire configuration array will be set. + * + * + * // Set the application timezone + * Config::set('application.timezone', 'America/Chicago'); + * + * // Set the application configuration array + * Config::set('application', array()); + * + * * @param string $key * @param mixed $value * @return void @@ -59,16 +79,16 @@ class Config { { list($module, $file, $key) = static::parse($key); - if (is_null($key) or ! static::load($module, $file)) + if ( ! static::load($module, $file)) { throw new \Exception("Error setting configuration option. Option [$key] is not defined."); } - static::$items[$module][$file][$key] = $value; + (is_null($key)) ? static::$items[$module][$file] = $value : static::$items[$module][$file][$key] = $value; } /** - * Parse a configuration key. + * Parse a configuration key into its module, file, and key segments. * * @param string $key * @return array