Commit 48acf1d2 authored by Taylor Otwell's avatar Taylor Otwell

Refactoring Config class to use Arr. Removed unnecessary comments.

parent 3015f24e
...@@ -29,34 +29,25 @@ class Config { ...@@ -29,34 +29,25 @@ class Config {
*/ */
public static function get($key, $default = null) public static function get($key, $default = null)
{ {
// ----------------------------------------------------- // If no "dot" is present in the key, return the entire configuration array.
// If no dot is in the key, we will just return the
// entire configuration array.
// -----------------------------------------------------
if(strpos($key, '.') === false) if(strpos($key, '.') === false)
{ {
static::load($key); static::load($key);
return (array_key_exists($key, static::$items)) ? static::$items[$key] : $default; return Arr::get(static::$items, $key, $default);
} }
list($file, $key) = static::parse($key); list($file, $key) = static::parse($key);
static::load($file); static::load($file);
// ----------------------------------------------------- // Verify that the configuration file actually exists.
// If the file doesn't exist, return the default.
// -----------------------------------------------------
if ( ! array_key_exists($file, static::$items)) if ( ! array_key_exists($file, static::$items))
{ {
return $default; return $default;
} }
// ----------------------------------------------------- return Arr::get(static::$items[$file], $key, $default);
// Return the configuration item. If the item doesn't
// exist, the default value will be returned.
// -----------------------------------------------------
return (array_key_exists($key, static::$items[$file])) ? static::$items[$file][$key] : $default;
} }
/** /**
...@@ -83,11 +74,9 @@ class Config { ...@@ -83,11 +74,9 @@ class Config {
*/ */
private static function parse($key) private static function parse($key)
{ {
// ----------------------------------------------------- // The left side of the dot is the file name, while the right side of the dot
// The left side of the dot is the file name, while // is the item within that file being requested.
// the right side of the dot is the item within that
// file being requested.
// -----------------------------------------------------
$segments = explode('.', $key); $segments = explode('.', $key);
if (count($segments) < 2) if (count($segments) < 2)
...@@ -99,25 +88,19 @@ class Config { ...@@ -99,25 +88,19 @@ class Config {
} }
/** /**
* Load all of the configuration items. * Load all of the configuration items from a file.
* *
* @param string $file * @param string $file
* @return void * @return void
*/ */
public static function load($file) public static function load($file)
{ {
// -----------------------------------------------------
// Bail out if already loaded or doesn't exist. // Bail out if already loaded or doesn't exist.
// -----------------------------------------------------
if (array_key_exists($file, static::$items) or ! file_exists($path = APP_PATH.'config/'.$file.EXT)) if (array_key_exists($file, static::$items) or ! file_exists($path = APP_PATH.'config/'.$file.EXT))
{ {
return; return;
} }
// -----------------------------------------------------
// Load the configuration array into the array of items.
// The items array is keyed by filename.
// -----------------------------------------------------
static::$items[$file] = require $path; static::$items[$file] = require $path;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment