Commit 56044d31 by Taylor Otwell

refactoring bootstrap process.

parent 1e49001d
......@@ -4,25 +4,6 @@ return array(
/*
|--------------------------------------------------------------------------
| Database Manager Auto Load
|--------------------------------------------------------------------------
|
| Determines if the database manager will be loaded one every request.
|
| By default, the database manager is loaded on every request and set on
| a property of the application instance. However, if you will not be using
| any of the Laravel database facilities, you may set this to "false".
|
| Loading the database manager does not create database connections. The
| connections are only established once you request a connection from the
| database manager instance.
|
*/
'autoload' => true,
/*
|--------------------------------------------------------------------------
| Default Database Connection
|--------------------------------------------------------------------------
|
......
......@@ -10,13 +10,6 @@ class Application {
public $request;
/**
* The application input manager.
*
* @var Input
*/
public $input;
/**
* The application configuration manager.
*
* @var Config
......@@ -31,25 +24,6 @@ class Application {
public $session;
/**
* The application cache manager.
*
* @var Cache\Driver
*/
public $cache;
/**
* The application database manager.
*/
public $database;
/**
* The application auto-loader.
*
* @var Loader
*/
public $loader;
/**
* The application IoC container.
*
* @var Container
......
<?php namespace Laravel;
// --------------------------------------------------------------
// Define the PHP file extension.
// --------------------------------------------------------------
define('EXT', '.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('SCRIPT_PATH', PUBLIC_PATH.'js/');
define('SESSION_PATH', STORAGE_PATH.'sessions/');
define('STYLE_PATH', PUBLIC_PATH.'css/');
define('SYS_CONFIG_PATH', SYS_PATH.'config/');
define('SYS_LANG_PATH', SYS_PATH.'language/');
define('VIEW_PATH', APP_PATH.'views/');
// --------------------------------------------------------------
// Bootstrap the application instance.
// --------------------------------------------------------------
require SYS_PATH.'application'.EXT;
......@@ -41,6 +73,6 @@ $application->container->instance('laravel.config', $application->config);
$application->container->instance('laravel.loader', $application->loader);
// --------------------------------------------------------------
// Set the global IoC container instance for emergency use.
// Set the IoC container instance for use as a service locator.
// --------------------------------------------------------------
IoC::$container = $application->container;
\ No newline at end of file
<?php
// --------------------------------------------------------------
// Define the PHP file extension.
// --------------------------------------------------------------
define('EXT', '.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('SCRIPT_PATH', PUBLIC_PATH.'js/');
define('SESSION_PATH', STORAGE_PATH.'sessions/');
define('STYLE_PATH', PUBLIC_PATH.'css/');
define('SYS_CONFIG_PATH', SYS_PATH.'config/');
define('SYS_LANG_PATH', SYS_PATH.'language/');
define('VIEW_PATH', APP_PATH.'views/');
\ No newline at end of file
......@@ -8,6 +8,16 @@ return array(
|--------------------------------------------------------------------------
*/
'laravel.database' => array('singleton' => true, 'resolver' => function($container)
{
$config = $container->resolve('laravel.config');
$connections = $config->get('database.connections');
return new Database\Manager($config->get('database.connections'), $config->get('database.default'));
}),
'laravel.file' => array('singleton' => true, 'resolver' => function($container)
{
return new File($container->resolve('laravel.config')->get('mimes'));
......@@ -36,6 +46,29 @@ return array(
}),
'laravel.input' => array('singleton' => true, 'resolver' => function($container)
{
$application = $container->resolve('laravel.application');
$input = array();
if ($application->request->method == 'GET')
{
$input = $_GET;
}
elseif ($application->request->method == 'POST')
{
$input = $_POST;
}
elseif ($application->request->method == 'PUT' or $application->request->method == 'DELETE')
{
($application->request->spoofed) ? $input = $_POST : parse_str(file_get_contents('php://input'), $input);
}
return new Input($input, $_FILES, new Cookie($_COOKIE));
}),
'laravel.package' => array('singleton' => true, 'resolver' => function()
{
return new Package;
......@@ -126,6 +159,17 @@ return array(
/*
|--------------------------------------------------------------------------
| Laravel Cache Manager
|--------------------------------------------------------------------------
*/
'laravel.cache' => array('singleton' => true, 'resolver' => function($container)
{
return new Cache\Manager($container, $container->resolve('laravel.config')->get('cache.driver'));
}),
/*
|--------------------------------------------------------------------------
| Laravel File Cache & Session Components
|--------------------------------------------------------------------------
*/
......
<?php namespace Laravel\Exception;
use Laravel\File;
class Examiner {
/**
* The exception being examined.
*
* @var Exception
*/
public $exception;
/**
* Human-readable error levels and descriptions.
*
* @var array
*/
private $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'
);
/**
* Create a new exception examiner instance.
*
* @param Exception $exception
* @return void
*/
public function __construct($exception)
{
$this->exception = $exception;
}
/**
* Get a human-readable version of the exception error code.
*
* @return string
*/
public function severity()
{
if (array_key_exists($this->exception->getCode(), $this->levels))
{
return $this->levels[$this->exception->getCode()];
}
return $this->exception->getCode();
}
/**
* Get the exception error message formatted for use by Laravel.
*
* The exception file paths will be shortened, and the file name and line number
* will be added to the exception message.
*
* @return string
*/
public function message()
{
$file = str_replace(array(APP_PATH, SYS_PATH), array('APP_PATH/', 'SYS_PATH/'), $this->exception->getFile());
return rtrim($this->exception->getMessage(), '.').' in '.$file.' on line '.$this->exception->getLine().'.';
}
/**
* Get the code surrounding the line where the exception occurred.
*
* @return array
*/
public function context()
{
list($path, $line) = array($this->exception->getFile(), $this->exception->getLine());
if ( ! file_exists($path)) return array();
$file = file($path, FILE_IGNORE_NEW_LINES);
array_unshift($file, '');
$start = $line - 5;
$length = ($line - $start) + 5 + 1;
return array_slice($file, ($start > 0) ? $start : 0, ($length > 0) ? $length : 0, true);
}
/**
* Magic Method to pass function calls to the exception.
*/
public function __call($method, $parameters)
{
return call_user_func_array(array($this->exception, $method), $parameters);
}
}
\ No newline at end of file
<?php namespace Laravel\Exception;
use Laravel\View;
use Laravel\Config;
use Laravel\Response;
class Handler {
/**
* The exception examiner for the exception being handled.
*
* @var Examiner
*/
public $examiner;
/**
* Create a new exception handler instance.
*
* @param Examiner $examiner
* @return void
*/
public function __construct(Examiner $examiner)
{
$this->examiner = $examiner;
}
/**
* Create a new exception handler instance.
*
* @param Examiner $examiner
* @return Handler
*/
public static function make(Examiner $examiner)
{
return new static($examiner);
}
/**
* Handle the exception and display the error report.
*
* The exception will be logged if error logging is enabled.
*
* The output buffer will be cleaned so nothing is sent to the browser except the
* error message. This prevents any views that have already been rendered from
* being shown in an incomplete or erroneous state.
*
* After the exception is displayed, the request will be halted.
*
* @return void
*/
public function handle()
{
if (ob_get_level() > 0) ob_clean();
if (Config::get('error.log')) $this->log();
$this->get_response(Config::get('error.detail'))->send();
exit(1);
}
/**
* Log the exception using the logger closure specified in the error configuration.
*
* @return void
*/
private function log()
{
$parameters = array($this->examiner->severity(), $this->examiner->message(), $this->examiner->getTraceAsString());
call_user_func_array(Config::get('error.logger'), $parameters);
}
/**
* Get the error report response for the exception.
*
* @param bool $detailed
* @return Resposne
*/
private function get_response($detailed)
{
return ($detailed) ? $this->detailed_response() : new Error('500');
}
/**
* Get the detailed error report for the exception.
*
* @return Response
*/
private function detailed_response()
{
$data = array(
'severity' => $this->examiner->severity(),
'message' => $this->examiner->message(),
'line' => $this->examiner->getLine(),
'trace' => $this->examiner->getTraceAsString(),
'contexts' => $this->examiner->context(),
);
return Response::make(View::make('error.exception', $data), 500);
}
}
\ No newline at end of file
<?php namespace Laravel;
// --------------------------------------------------------------
// Define the framework constants.
// Bootstrap the core framework components.
// --------------------------------------------------------------
require 'bootstrap/constants.php';
// --------------------------------------------------------------
// Load the application and the core application components.
// --------------------------------------------------------------
require SYS_PATH.'bootstrap/core'.EXT;
require 'bootstrap.php';
// --------------------------------------------------------------
// Set the error reporting and display levels.
......@@ -55,49 +50,6 @@ $application->request = new Request($_SERVER, $application->config->get('applica
$application->container->instance('laravel.request', $application->request);
// --------------------------------------------------------------
// Hydrate the input for the current request.
// --------------------------------------------------------------
$input = array();
if ($application->request->method == 'GET')
{
$input = $_GET;
}
elseif ($application->request->method == 'POST')
{
$input = $_POST;
}
elseif ($application->request->method == 'PUT' or $application->request->method == 'DELETE')
{
($application->request->spoofed) ? $input = $_POST : parse_str(file_get_contents('php://input'), $input);
}
$application->input = new Input($input, $_FILES, new Cookie($_COOKIE));
$application->container->instance('laravel.input', $application->input);
// --------------------------------------------------------------
// Load the cache manager.
// --------------------------------------------------------------
$application->cache = new Cache\Manager($application->container, $application->config->get('cache.driver'));
$application->container->instance('laravel.cache.manager', $application->cache);
// --------------------------------------------------------------
// Load the database manager.
// --------------------------------------------------------------
if ($application->config->get('database.autoload'))
{
$connections = $application->config->get('database.connections');
$application->database = new Database\Manager($connections, $application->config->get('database.default'));
$application->container->instance('laravel.database.manager', $application->database);
unset($connections);
}
// --------------------------------------------------------------
// Load the session and session manager.
// --------------------------------------------------------------
if ($application->config->get('session.driver') !== '')
......
......@@ -7,7 +7,7 @@
* @author Taylor Otwell <taylorotwell@gmail.com>
* @link http://laravel.com
*/
$t = microtime(true);
/*
|--------------------------------------------------------------------------
| Installation Paths
......@@ -36,4 +36,6 @@ $public = __DIR__;
| 3... 2... 1... Lift-off!
|--------------------------------------------------------------------------
*/
require $laravel.'/laravel.php';
\ No newline at end of file
require $laravel.'/laravel.php';
echo (microtime(true) - $t) * 1000;
\ No newline at end of file
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