refactoring config class.
This commit is contained in:
parent
16a1f89929
commit
68e3b468cf
|
@ -64,7 +64,7 @@ public static function set($key, $value)
|
||||||
|
|
||||||
if (is_null($key) or ! static::load($module, $file))
|
if (is_null($key) or ! static::load($module, $file))
|
||||||
{
|
{
|
||||||
throw new \Exception("Unable to find configuration file item [$key].");
|
throw new \Exception("Error setting configuration option. Option [$key] is not defined.");
|
||||||
}
|
}
|
||||||
|
|
||||||
static::$items[$module][$file][$key] = $value;
|
static::$items[$module][$file][$key] = $value;
|
||||||
|
@ -85,8 +85,6 @@ private static function parse($key)
|
||||||
// the configuration key, otherwise, we will use "application" as the module.
|
// 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 the configuration item is stored in a module, we need to strip the module qualifier
|
|
||||||
// off of the configuration key before continuing.
|
|
||||||
if ($module != 'application')
|
if ($module != 'application')
|
||||||
{
|
{
|
||||||
$key = substr($key, strpos($key, ':') + 2);
|
$key = substr($key, strpos($key, ':') + 2);
|
||||||
|
@ -94,8 +92,6 @@ private static function parse($key)
|
||||||
|
|
||||||
$segments = explode('.', $key);
|
$segments = explode('.', $key);
|
||||||
|
|
||||||
// If there is more than one segment, we need to splice together and portion of the
|
|
||||||
// configuration key that comes after the first segment, which is the file name.
|
|
||||||
$key = (count($segments) > 1) ? implode('.', array_slice($segments, 1)) : null;
|
$key = (count($segments) > 1) ? implode('.', array_slice($segments, 1)) : null;
|
||||||
|
|
||||||
return array($module, $segments[0], $key);
|
return array($module, $segments[0], $key);
|
||||||
|
@ -113,8 +109,6 @@ private static function parse($key)
|
||||||
*/
|
*/
|
||||||
public static function load($module, $file)
|
public static function load($module, $file)
|
||||||
{
|
{
|
||||||
// If the configuration items for this module and file have already been
|
|
||||||
// loaded, we can bail out of this method.
|
|
||||||
if (isset(static::$items[$module]) and array_key_exists($file, static::$items[$module])) return true;
|
if (isset(static::$items[$module]) and array_key_exists($file, static::$items[$module])) return true;
|
||||||
|
|
||||||
$path = ($module === 'application') ? CONFIG_PATH : MODULE_PATH.$module.'/config/';
|
$path = ($module === 'application') ? CONFIG_PATH : MODULE_PATH.$module.'/config/';
|
||||||
|
|
Loading…
Reference in New Issue