refactoring.

This commit is contained in:
Taylor Otwell
2011-09-21 21:46:16 -05:00
parent b9b9711921
commit 0c4018ec88
42 changed files with 980 additions and 1330 deletions

View File

@@ -0,0 +1,91 @@
<?php namespace Laravel;
// --------------------------------------------------------------
// Define the PHP file extensions.
// --------------------------------------------------------------
define('EXT', '.php');
define('BLADE_EXT', '.blade.php');
// --------------------------------------------------------------
// Define the core framework paths.
// --------------------------------------------------------------
define('APP_PATH', realpath($application).'/');
define('BASE_PATH', realpath(str_replace('laravel', '', $laravel)).'/');
define('PACKAGE_PATH', realpath($packages).'/');
define('PUBLIC_PATH', realpath($public).'/');
define('STORAGE_PATH', realpath($storage).'/');
define('SYS_PATH', realpath($laravel).'/');
unset($laravel, $application, $config, $packages, $public, $storage);
// --------------------------------------------------------------
// Define various other framework paths.
// --------------------------------------------------------------
define('CACHE_PATH', STORAGE_PATH.'cache/');
define('CONFIG_PATH', APP_PATH.'config/');
define('CONTROLLER_PATH', APP_PATH.'controllers/');
define('DATABASE_PATH', STORAGE_PATH.'database/');
define('LANG_PATH', APP_PATH.'language/');
define('ROUTE_PATH', APP_PATH.'routes/');
define('SESSION_PATH', STORAGE_PATH.'sessions/');
define('SYS_CONFIG_PATH', SYS_PATH.'config/');
define('SYS_LANG_PATH', SYS_PATH.'language/');
define('VIEW_PATH', APP_PATH.'views/');
// --------------------------------------------------------------
// Load the configuration manager and its dependencies.
// --------------------------------------------------------------
require SYS_PATH.'facades'.EXT;
require SYS_PATH.'config'.EXT;
require SYS_PATH.'loader'.EXT;
require SYS_PATH.'arr'.EXT;
// --------------------------------------------------------------
// Determine the application environment.
// --------------------------------------------------------------
$environment = (isset($_SERVER['LARAVEL_ENV'])) ? $_SERVER['LARAVEL_ENV'] : null;
// --------------------------------------------------------------
// Register the configuration file paths.
// --------------------------------------------------------------
$config = array(SYS_CONFIG_PATH, CONFIG_PATH);
if ( ! is_null($environment)) $config[] = CONFIG_PATH.$environment.'/';
Config::paths($config);
// --------------------------------------------------------------
// Set a few core configuration options.
// --------------------------------------------------------------
Config::set('view.path', VIEW_PATH);
// --------------------------------------------------------------
// Bootstrap the IoC container.
// --------------------------------------------------------------
require SYS_PATH.'container'.EXT;
$container = new Container(Config::get('container'));
IoC::$container = $container;
// --------------------------------------------------------------
// Register the auto-loader on the auto-loader stack.
// --------------------------------------------------------------
spl_autoload_register(array('Laravel\\Loader', 'load'));
Loader::$paths = array(BASE_PATH, APP_PATH.'models/', APP_PATH);
Loader::$aliases = Config::get('aliases');
// --------------------------------------------------------------
// Define some convenient global functions.
// --------------------------------------------------------------
function e($value)
{
return HTML::entities($value);
}
function __($key, $replacements = array(), $language = null)
{
return Lang::line($key, $replacements, $language);
}

View File

@@ -0,0 +1,73 @@
<?php namespace Laravel;
/**
* Create the exception formatter closure. This function will format
* the exception message and severity for display and return the
* two formatted strings in an array.
*/
$formatter = function($e)
{
$levels = array(
0 => 'Error',
E_ERROR => 'Error',
E_WARNING => 'Warning',
E_PARSE => 'Parsing Error',
E_NOTICE => 'Notice',
E_CORE_ERROR => 'Core Error',
E_CORE_WARNING => 'Core Warning',
E_COMPILE_ERROR => 'Compile Error',
E_COMPILE_WARNING => 'Compile Warning',
E_USER_ERROR => 'User Error',
E_USER_WARNING => 'User Warning',
E_USER_NOTICE => 'User Notice',
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);
};
/**
* Create the exception handler function. All of the handlers registered
* with PHP will call this handler when an error occurs, giving us a common
* spot to put error handling logic.
*/
$handler = function($e) use ($formatter)
{
list($severity, $message) = $formatter($e);
call_user_func(Config::get('error.handler'), $e, $severity, $message, Config::get('error'));
};
/**
* Register the exception, error, and shutdown error handlers.
*/
set_exception_handler(function($e) use ($handler)
{
$handler($e);
});
set_error_handler(function($number, $error, $file, $line) use ($handler)
{
$handler(new \ErrorException($error, $number, 0, $file, $line));
});
register_shutdown_function(function() use ($handler)
{
if ( ! is_null($error = error_get_last()))
{
$handler(new \ErrorException($error['message'], $error['type'], 0, $error['file'], $error['line']));
}
});
/**
* Set the error reporting and display levels.
*/
error_reporting(-1);
ini_set('display_errors', 'Off');