Commit e39ab9a0 authored by Taylor Otwell's avatar Taylor Otwell

Refactor the config class.

parent ee5212a2
...@@ -38,7 +38,10 @@ class Config { ...@@ -38,7 +38,10 @@ class Config {
{ {
list($module, $file, $key) = static::parse($key); list($module, $file, $key) = static::parse($key);
if ( ! static::load($module, $file)) return is_callable($default) ? call_user_func($default) : $default; if ( ! static::load($module, $file))
{
return is_callable($default) ? call_user_func($default) : $default;
}
if (is_null($key)) return static::$items[$module][$file]; if (is_null($key)) return static::$items[$module][$file];
...@@ -77,7 +80,10 @@ class Config { ...@@ -77,7 +80,10 @@ class Config {
{ {
$module = (strpos($key, '::') !== false) ? substr($key, 0, strpos($key, ':')) : 'application'; $module = (strpos($key, '::') !== false) ? substr($key, 0, strpos($key, ':')) : 'application';
if ($module !== 'application') $key = substr($key, strpos($key, ':') + 2); if ($module !== 'application')
{
$key = substr($key, strpos($key, ':') + 2);
}
$key = (count($segments = explode('.', $key)) > 1) ? implode('.', array_slice($segments, 1)) : null; $key = (count($segments = explode('.', $key)) > 1) ? implode('.', array_slice($segments, 1)) : null;
...@@ -87,9 +93,6 @@ class Config { ...@@ -87,9 +93,6 @@ class Config {
/** /**
* Load all of the configuration items from a file. * Load all of the configuration items from a file.
* *
* If it exists, the configuration file in the application/config directory will be loaded first.
* Any environment specific configuration files will be merged with the root file.
*
* @param string $file * @param string $file
* @param string $module * @param string $module
* @return bool * @return bool
...@@ -100,8 +103,10 @@ class Config { ...@@ -100,8 +103,10 @@ class Config {
$path = ($module === 'application') ? CONFIG_PATH : MODULE_PATH.$module.'/config/'; $path = ($module === 'application') ? CONFIG_PATH : MODULE_PATH.$module.'/config/';
// Load the base configuration items from the application directory.
$config = (file_exists($base = $path.$file.EXT)) ? require $base : array(); $config = (file_exists($base = $path.$file.EXT)) ? require $base : array();
// Merge any environment specific configuration into the base array.
if (isset($_SERVER['LARAVEL_ENV']) and file_exists($path = $path.$_SERVER['LARAVEL_ENV'].'/'.$file.EXT)) if (isset($_SERVER['LARAVEL_ENV']) and file_exists($path = $path.$_SERVER['LARAVEL_ENV'].'/'.$file.EXT))
{ {
$config = array_merge($config, require $path); $config = array_merge($config, 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