Commit be954961 authored by Taylor Otwell's avatar Taylor Otwell

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: 's avatarTaylor Otwell <taylorotwell@gmail.com>
parent 871d205a
......@@ -66,21 +66,4 @@ return array(
Log::exception($exception);
},
/*
|--------------------------------------------------------------------------
| PHP INI Display Errors Setting
|--------------------------------------------------------------------------
|
| Here you may specify the display_errors setting of the PHP.ini file.
| Typically you may keep this "Off", as Laravel will cleanly handle
| the display of all errors.
|
| However, if you encounter an infamous white screen of death scenario,
| turning this "On" may help you solve the problem by getting the
| real error message being thrown by the application.
|
*/
'display' => 'Off',
);
\ No newline at end of file
<?php
/*
|--------------------------------------------------------------------------
| PHP Display Errors Configuration
|--------------------------------------------------------------------------
|
| Since Laravel intercepts and displays all errors with a detailed stack
| trace, we can turn off the display_errors ini directive. However, you
| may want to enable this option if you ever run into a dreaded white
| screen of death, as it can provide some clues.
|
*/
ini_set('display_errors', 'Off');
/*
|--------------------------------------------------------------------------
| Register Class Aliases
|--------------------------------------------------------------------------
|
| Aliases allow you to use classes without always specifying their fully
| namespaced path. This is convenient for working with any library that
| makes a heavy use of namespace for class organization. Here we will
| simply register the configured class aliases.
|
*/
$aliases = Laravel\Config::get('application.aliases');
Laravel\Autoloader::$aliases = $aliases;
/*
|--------------------------------------------------------------------------
| Set The Default Timezone
|--------------------------------------------------------------------------
|
| We need to set the default timezone for the application. This controls
| the timezone that will be used by any of the date methods and classes
| utilized by Laravel or your application. The timezone may be set in
| your application configuration file.
|
*/
date_default_timezone_set(Config::get('application.timezone'));
/*
|--------------------------------------------------------------------------
| Start / Load The User Session
|--------------------------------------------------------------------------
|
| Sessions allow the web, which is stateless, to simulate state. In other
| words, sessions allow you to store information about the current user
| and state of your application. Here we'll just fire up the session
| if a session driver has been configured.
|
*/
if (Config::get('session.driver') !== '')
{
Session::load();
}
/*
|--------------------------------------------------------------------------
| Auto-Loader Mappings
......
......@@ -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;
}
/**
......
......@@ -64,26 +64,9 @@ if (isset($_SERVER['CLI']['ENV']))
}
/**
* Register all of the core class aliases. These aliases provide a
* convenient way of working with the Laravel core classes without
* having to worry about the namespacing. The developer is also
* free to remove aliases when they extend core classes.
*/
Autoloader::$aliases = Config::get('application.aliases');
/**
* Register the default timezone for the application. This will
* be the default timezone used by all date functions through
* throughout the entire application.
*/
$timezone = Config::get('application.timezone');
date_default_timezone_set($timezone);
/**
* Finally we'll grab all of the bundles and register them
* with the bundle class. All of the bundles are stored in
* an array within the application directory.
* Finally we'll grab all of the bundles and register them with the
* bundle class. All of the bundles are stored in an array within
* the application directory which defines all bundles.
*/
$bundles = require path('app').'bundles'.EXT;
......
......@@ -50,8 +50,6 @@ register_shutdown_function(function()
*/
error_reporting(-1);
ini_set('display_errors', Config::get('error.display'));
/**
* Even though "Magic Quotes" are deprecated in PHP 5.3, they may
* still be enabled on the server. To account for this, we will
......@@ -68,18 +66,6 @@ if (magic_quotes())
}
}
/**
* Load the session using the session manager. The payload will
* be set on a static property of the Session class for easy
* access throughout the framework and application.
*/
if (Config::get('session.driver') !== '')
{
Session::start(Config::get('session.driver'));
Session::load(Cookie::get(Config::get('session.cookie')));
}
/**
* Gather the input to the application based on the global input
* variables for the current request. The input will be gathered
......
......@@ -17,7 +17,19 @@ class Session {
const csrf_token = 'csrf_token';
/**
* Create the session payload instance and load the session for the request.
* Create the session payload and the load the session.
*
* @return void
*/
public static function load()
{
static::start(Config::get('session.driver'));
static::$instance->load(Cookie::get(Config::get('session.cookie')));
}
/**
* Create the session payload instance for the request.
*
* @param string $driver
* @return void
......
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