From 5a4e6ebc75aecade44ccf2e13227fcba1636fbed Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 16 Jun 2011 20:21:23 -0500 Subject: [PATCH] improved comments in config class. --- system/config.php | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/system/config.php b/system/config.php index 25c8c311..5c2d506e 100644 --- a/system/config.php +++ b/system/config.php @@ -17,17 +17,16 @@ class Config { */ public static function get($key) { - // ----------------------------------------------------- - // Parse the key to separate the file and key name. - // ----------------------------------------------------- list($file, $key) = static::parse($key); - // ----------------------------------------------------- - // Load the appropriate configuration file. - // ----------------------------------------------------- static::load($file); - return (array_key_exists($key, static::$items[$file])) ? static::$items[$file][$key] : null; + if (array_key_exists($key, static::$items[$file])) + { + return static::$items[$file][$key]; + } + + throw new \Exception("Configuration item [$key] is not defined."); } /** @@ -39,14 +38,8 @@ public static function get($key) */ public static function set($key, $value) { - // ----------------------------------------------------- - // Parse the key to separate the file and key name. - // ----------------------------------------------------- list($file, $key) = static::parse($key); - // ----------------------------------------------------- - // Load the appropriate configuration file. - // ----------------------------------------------------- static::load($file); static::$items[$file][$key] = $value; @@ -60,6 +53,14 @@ public static function set($key, $value) */ private static function parse($key) { + // ----------------------------------------------------- + // The left side of the dot is the file name, while + // the right side of the dot is the item within that + // file being requested. + // + // This syntax allows for the easy retrieval and setting + // of configuration items. + // ----------------------------------------------------- $segments = explode('.', $key); if (count($segments) < 2) @@ -67,11 +68,6 @@ private static function parse($key) throw new \Exception("Invalid configuration key [$key]."); } - // ----------------------------------------------------- - // The left side of the dot is the file name, while - // the right side of the dot is the item within that - // file being requested. - // ----------------------------------------------------- return array($segments[0], implode('.', array_slice($segments, 1))); } @@ -96,6 +92,10 @@ public static function load($file) throw new \Exception("Configuration file [$file] does not exist."); } + // ----------------------------------------------------- + // Load the configuration array into the array of items. + // The items array is keyed by filename. + // ----------------------------------------------------- static::$items[$file] = require $path; }