Allowing for config.load event.
Moved more basic logic into application start to make it easier to hook into early life cycle events such as configuration loading while not introducing extra files into the framework. Signed-off-by: Taylor Otwell <taylorotwell@gmail.com>
This commit is contained in:
@@ -20,6 +20,13 @@ class Config {
|
||||
*/
|
||||
public static $cache = array();
|
||||
|
||||
/**
|
||||
* The configuration loader event name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const loader = 'laravel.config.loader';
|
||||
|
||||
/**
|
||||
* Determine if a configuration item or file exists.
|
||||
*
|
||||
@@ -106,8 +113,7 @@ class Config {
|
||||
|
||||
// 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.
|
||||
// array for the bundle into the array_set method.
|
||||
if (is_null($item))
|
||||
{
|
||||
array_set(static::$items[$bundle], $file, $value);
|
||||
@@ -166,6 +172,38 @@ class Config {
|
||||
{
|
||||
if (isset(static::$items[$bundle][$file])) return true;
|
||||
|
||||
// We allow a "config.loader" event to be registered which is responsible for
|
||||
// returning an array representing the configuration for the bundle and file
|
||||
// requested. This allows many types of config "drivers".
|
||||
if (Event::listeners(static::loader))
|
||||
{
|
||||
$config = Event::first(static::loader, func_get_args());
|
||||
}
|
||||
else
|
||||
{
|
||||
$config = static::file($bundle, $file);
|
||||
}
|
||||
|
||||
// If configuration items were actually found for the bundle and file we
|
||||
// will add them to the configuration array and return true, otherwise
|
||||
// we will return false indicating the file was not found.
|
||||
if (count($config) > 0)
|
||||
{
|
||||
static::$items[$bundle][$file] = $config;
|
||||
}
|
||||
|
||||
return isset(static::$items[$bundle][$file]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the configuration items from a configuration file.
|
||||
*
|
||||
* @param string $bundle
|
||||
* @param string $file
|
||||
* @return array
|
||||
*/
|
||||
public static function file($bundle, $file)
|
||||
{
|
||||
$config = array();
|
||||
|
||||
// Configuration files cascade. Typically, the bundle configuration array is
|
||||
@@ -179,12 +217,7 @@ class Config {
|
||||
}
|
||||
}
|
||||
|
||||
if (count($config) > 0)
|
||||
{
|
||||
static::$items[$bundle][$file] = $config;
|
||||
}
|
||||
|
||||
return isset(static::$items[$bundle][$file]);
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user