diff --git a/application/config/container.php b/application/config/container.php new file mode 100644 index 00000000..2e9b5ef0 --- /dev/null +++ b/application/config/container.php @@ -0,0 +1,54 @@ + function($c) + | { + | return new Mailer($sender, $key); + | } + | + | Note that the container instance itself is passed into the resolver, + | allowing you to continue to resolve dependencies within the resolver + | itself. This allows you to easily resolve nested dependencies. + | + | When creating controller instances, Laravel will check to see if a + | resolver has been registered for the controller. If it has, it will + | be used to create the controller instance. All controller resolvers + | should be registered beginning using a {controllers}.{name} naming + | convention. For example: + | + | 'controllers.user' => function($c) + | { + | return new User_Controller($c->resolve('repository')); + | } + | + | Of course, sometimes you may wish to register an object as a singleton + | Singletons are resolved by the controller the first time they are + | resolved; however, that same resolved instance will continue to be + | returned by the container each time it is requested. Registering an + | object as a singleton couldn't be simpler: + | + | 'mailer' => array('singleton' => true, 'resolver' => function($c) + | { + | return new Mailer($sender, $key); + | }) + | + */ + +); \ No newline at end of file diff --git a/laravel/bootstrap/constants.php b/laravel/bootstrap/constants.php index 56710afb..d6dd3b20 100644 --- a/laravel/bootstrap/constants.php +++ b/laravel/bootstrap/constants.php @@ -1,8 +1,17 @@ $value) @@ -11,6 +20,11 @@ function constants($constants) } } +/** + * Register the core framework paths. All other paths are + * built on top of these core paths. All of these paths are + * changable by the developer in the front controller. + */ $constants = array( 'APP_PATH' => realpath($application).'/', 'BASE_PATH' => realpath("$laravel/..").'/', @@ -22,6 +36,10 @@ function constants($constants) constants($constants); +/** + * Register all of the other framework paths. All of these + * paths are built on top of the core paths above. + */ $constants = array( 'CACHE_PATH' => STORAGE_PATH.'cache/', 'CONFIG_PATH' => APP_PATH.'config/', @@ -41,4 +59,15 @@ function constants($constants) constants($constants); -unset($constants); \ No newline at end of file +unset($constants); + +/** + * Set the Laravel environment configuration path constant. + * The environment is controller by setting an environment + * variable on the server running Laravel. + */ +$environment = (isset($_SERVER['LARAVEL_ENV'])) ? $_SERVER['LARAVEL_ENV'] : ''; + +define('ENV_CONFIG_PATH', $environment); + +unset($environment); \ No newline at end of file diff --git a/laravel/bootstrap/core.php b/laravel/bootstrap/core.php index 3d758081..883c4942 100644 --- a/laravel/bootstrap/core.php +++ b/laravel/bootstrap/core.php @@ -11,49 +11,14 @@ require SYS_PATH.'config'.EXT; require SYS_PATH.'loader'.EXT; -/** - * If a Laravel environment has been specified on the server, we will - * add a path to the configuration manager for the environment. - */ -if (isset($_SERVER['LARAVEL_ENV'])) -{ - define('ENV_CONFIG_PATH', CONFIG_PATH.$_SERVER['LARAVEL_ENV'].'/'); - - Config::glance(ENV_CONFIG_PATH); -} - /** * Load some core configuration files by default so we don't have to - * let them fall through the Config loader. This will allow us to + * let them fall through the Config parser. This will allow us to * load these files faster for each request. */ -foreach (array('application', 'session') as $file) -{ - $config = require CONFIG_PATH.$file.EXT; - - if (isset($_SERVER['LARAVEL_ENV']) and file_exists($path = ENV_CONFIG_PATH.$file.EXT)) - { - $config = array_merge($config, require $path); - } - - Config::$items[$file] = $config; -} - -/** - * Load the container configuration into the Config class. We load - * this file manually to avoid the overhead of Config::load. - */ -Config::$items['container'] = require SYS_CONFIG_PATH.'container'.EXT; - -if (file_exists($path = CONFIG_PATH.'container'.EXT)) -{ - Config::$items['container'] = array_merge(Config::$items['container'], require $path); -} - -if (isset($_SERVER['LARAVEL_ENV']) and file_exists($path = ENV_CONFIG_PATH.'container'.EXT)) -{ - Config::$items['container'] = array_merge(Config::$items['container'], require $path); -} +Config::load('application'); +Config::load('container'); +Config::load('session'); /** * Bootstrap the application inversion of control (IoC) container. @@ -67,7 +32,7 @@ IoC::$container = $container; -unset($config, $container); +unset($container); /** * Register the application auto-loader. The auto-loader is responsible @@ -79,7 +44,9 @@ Loader::$aliases = Config::$items['application']['aliases']; /** - * Define a few convenient global functions. + * Define a few convenient global functions. These functions primarily + * exists to provide a short way of accessing functions commonly used + * in views, allowing the reduction of code noise. */ function e($value) { diff --git a/laravel/bootstrap/errors.php b/laravel/bootstrap/errors.php index 0291cb5d..51b0529e 100644 --- a/laravel/bootstrap/errors.php +++ b/laravel/bootstrap/errors.php @@ -1,11 +1,23 @@ getFile()); + + return rtrim($e->getMessage(), '.').' in '.$file.' on line '.$e->getLine().'.'; +}; + +/** + * Define a clousre that will return a more readable version + * of the severity of an exception. This function will be used + * by the error handler when parsing exceptions. + */ +$severity = function($e) { $levels = array( 0 => 'Error', @@ -23,31 +35,25 @@ E_STRICT => 'Runtime Notice', ); - $file = str_replace(array(APP_PATH, SYS_PATH), array('APP_PATH/', 'SYS_PATH/'), $e->getFile()); - - $message = rtrim($e->getMessage(), '.').' in '.$file.' on line '.$e->getLine().'.'; - - $severity = (array_key_exists($e->getCode(), $levels)) ? $levels[$e->getCode()] : $e->getCode(); - - return array($severity, $message); + return (array_key_exists($e->getCode(), $levels)) ? $levels[$e->getCode()] : $e->getCode(); }; /** * Create the exception handler function. All of the error handlers * registered with PHP call this closure to keep the code D.R.Y. + * Each of the formatting closures defined above will be passed + * into the handler for convenient use. */ -$handler = function($e) use ($formatter) +$handler = function($e) use ($message, $severity) { - list($severity, $message) = $formatter($e); - $config = Config::get('error'); if ($config['log']) { - call_user_func($config['logger'], $e, $severity, $message, $config); + call_user_func($config['logger'], $e, $severity($e), $message($e), $config); } - call_user_func($config['handler'], $e, $severity, $message, $config); + call_user_func($config['handler'], $e, $severity($e), $message($e), $config); exit(1); }; diff --git a/laravel/config.php b/laravel/config.php index 9c2bfc4a..f19444af 100644 --- a/laravel/config.php +++ b/laravel/config.php @@ -16,7 +16,7 @@ class Config { * * @var array */ - public static $paths = array(SYS_CONFIG_PATH, CONFIG_PATH); + public static $paths = array(SYS_CONFIG_PATH, CONFIG_PATH, ENV_CONFIG_PATH); /** * Determine if a configuration item or file exists. @@ -130,7 +130,7 @@ protected static function parse($key) * @param string $file * @return bool */ - protected static function load($file) + public static function load($file) { if (isset(static::$items[$file])) return true; @@ -141,7 +141,7 @@ protected static function load($file) // cascading of configuration options from system to application. foreach (static::$paths as $directory) { - if (file_exists($path = $directory.$file.EXT)) + if ($directory !== '' and file_exists($path = $directory.$file.EXT)) { $config = array_merge($config, require $path); }