Commit c81be6d2 authored by Taylor Otwell's avatar Taylor Otwell

fix config class bug.

parent c44b6264
...@@ -60,14 +60,6 @@ class Config { ...@@ -60,14 +60,6 @@ class Config {
*/ */
public static function get($key) public static function get($key)
{ {
// First, we'll check the keyed cache of configuration items, as this will
// be the fastest method of retrieving the configuration option. After an
// item is retrieved, it is always stored in the cache by its key.
if (array_key_exists($key, static::$cache))
{
return static::$cache[$key];
}
list($bundle, $file, $item) = static::parse($key); list($bundle, $file, $item) = static::parse($key);
if ( ! static::load($bundle, $file)) return; if ( ! static::load($bundle, $file)) return;
...@@ -77,9 +69,14 @@ class Config { ...@@ -77,9 +69,14 @@ class Config {
// If a specific configuration item was not requested, the key will be null, // If a specific configuration item was not requested, the key will be null,
// meaning we need to return the entire array of configuration item from the // meaning we need to return the entire array of configuration item from the
// requested configuration file. Otherwise we can return the item. // requested configuration file. Otherwise we can return the item.
$value = (is_null($item)) ? $items : array_get($items, $item); if (is_null($item))
{
return static::$cache[$key] = $value; return $items;
}
else
{
return array_get($items, $item);
}
} }
/** /**
...@@ -102,7 +99,22 @@ class Config { ...@@ -102,7 +99,22 @@ class Config {
*/ */
public static function set($key, $value) public static function set($key, $value)
{ {
static::$cache[$key] = $value; list($bundle, $file, $item) = static::parse($key);
static::load($bundle, $file);
// If the item is null, it means the developer wishes to set the entire
// configuration array to a given value, so we will pass the entire
// array for the bundle into the array_set method, otherwise we'll
// only pass the file array for the bundle.
if (is_null($item))
{
array_set(static::$items[$bundle], $file, $value);
}
else
{
array_set(static::$items[$bundle][$file], $item, $value);
}
} }
/** /**
...@@ -115,6 +127,14 @@ class Config { ...@@ -115,6 +127,14 @@ class Config {
*/ */
protected static function parse($key) protected static function parse($key)
{ {
// First, we'll check the keyed cache of configuration items, as this will
// be the fastest method of retrieving the configuration option. After an
// item is parsed, it is always stored in the cache by its key.
if (array_key_exists($key, static::$cache))
{
return static::$cache[$key];
}
$bundle = Bundle::name($key); $bundle = Bundle::name($key);
$segments = explode('.', Bundle::element($key)); $segments = explode('.', Bundle::element($key));
...@@ -124,12 +144,14 @@ class Config { ...@@ -124,12 +144,14 @@ class Config {
// If that is the case, we'll make the item field of the array "null". // If that is the case, we'll make the item field of the array "null".
if (count($segments) >= 2) if (count($segments) >= 2)
{ {
return array($bundle, $segments[0], implode('.', array_slice($segments, 1))); $parsed = array($bundle, $segments[0], implode('.', array_slice($segments, 1)));
} }
else else
{ {
return array($bundle, $segments[0], null); $parsed = array($bundle, $segments[0], null);
} }
return static::$cache[$key] = $parsed;
} }
/** /**
......
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