Commit 9018d6cc authored by Taylor Otwell's avatar Taylor Otwell

Refactoring the Config class.

parent fe39d507
...@@ -38,15 +38,11 @@ class Config { ...@@ -38,15 +38,11 @@ class Config {
{ {
list($module, $file, $key) = static::parse($key); list($module, $file, $key) = static::parse($key);
if ( ! static::load($module, $file)) // If the configuration file doesn't exist, return the default value.
{ if ( ! static::load($module, $file)) return is_callable($default) ? call_user_func($default) : $default;
return is_callable($default) ? call_user_func($default) : $default;
}
if (is_null($key)) // If no key was specified, return the entire configuration array.
{ if (is_null($key)) return static::$items[$module][$file];
return static::$items[$module][$file];
}
return Arr::get(static::$items[$module][$file], $key, $default); return Arr::get(static::$items[$module][$file], $key, $default);
} }
...@@ -81,14 +77,9 @@ class Config { ...@@ -81,14 +77,9 @@ class Config {
*/ */
private static function parse($key) private static function parse($key)
{ {
// Check for a module qualifier. If a module name is present, we need to extract it from
// the configuration key, otherwise, we will use "application" as the module.
$module = (strpos($key, '::') !== false) ? substr($key, 0, strpos($key, ':')) : 'application'; $module = (strpos($key, '::') !== false) ? substr($key, 0, strpos($key, ':')) : 'application';
if ($module != 'application') if ($module !== 'application') $key = substr($key, strpos($key, ':') + 2);
{
$key = substr($key, strpos($key, ':') + 2);
}
$segments = explode('.', $key); $segments = explode('.', $key);
...@@ -122,10 +113,7 @@ class Config { ...@@ -122,10 +113,7 @@ class Config {
$config = array_merge($config, require $path); $config = array_merge($config, require $path);
} }
if (count($config) > 0) if (count($config) > 0) static::$items[$module][$file] = $config;
{
static::$items[$module][$file] = $config;
}
return isset(static::$items[$module][$file]); return isset(static::$items[$module][$file]);
} }
......
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