Refactor the config class.
This commit is contained in:
parent
ee5212a27f
commit
e39ab9a0f9
|
@ -38,7 +38,10 @@ public static function get($key, $default = null)
|
|||
{
|
||||
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];
|
||||
|
||||
|
@ -77,7 +80,10 @@ private static function parse($key)
|
|||
{
|
||||
$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;
|
||||
|
||||
|
@ -87,9 +93,6 @@ private static function parse($key)
|
|||
/**
|
||||
* 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 $module
|
||||
* @return bool
|
||||
|
@ -100,8 +103,10 @@ public static function load($module, $file)
|
|||
|
||||
$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();
|
||||
|
||||
// Merge any environment specific configuration into the base array.
|
||||
if (isset($_SERVER['LARAVEL_ENV']) and file_exists($path = $path.$_SERVER['LARAVEL_ENV'].'/'.$file.EXT))
|
||||
{
|
||||
$config = array_merge($config, require $path);
|
||||
|
|
Loading…
Reference in New Issue