refactoring for better dependency injection on a few classes.

This commit is contained in:
Taylor Otwell
2011-10-29 22:24:32 -05:00
parent faaea17fd3
commit 932a70b6cf
13 changed files with 248 additions and 105 deletions

View File

@@ -37,52 +37,12 @@ if (Config::$items['session']['driver'] !== '')
* Manually load some core classes that are used on every request
* This allows to avoid using the loader for these classes.
*/
require SYS_PATH.'uri'.EXT;
require SYS_PATH.'input'.EXT;
require SYS_PATH.'request'.EXT;
require SYS_PATH.'response'.EXT;
require SYS_PATH.'routing/route'.EXT;
require SYS_PATH.'routing/router'.EXT;
require SYS_PATH.'routing/loader'.EXT;
require SYS_PATH.'routing/filter'.EXT;
/**
* Gather the input to the application for the current request.
* The input will be gathered based on the current request method
* and will be set on the Input manager.
*/
$input = array();
switch (Request::method())
{
case 'GET':
$input = $_GET;
break;
case 'POST':
$input = $_POST;
break;
case 'PUT':
case 'DELETE':
if (Request::spoofed())
{
$input = $_POST;
}
else
{
parse_str(file_get_contents('php://input'), $input);
}
}
/**
* The spoofed request method is removed from the input so it is
* not unexpectedly included in Input::all() or Input::get().s
*/
unset($input[Request::spoofer]);
Input::$input = $input;
/**
* Route the request to the proper route in the application. If a
* route is found, the route will be called with the current request
@@ -91,13 +51,13 @@ Input::$input = $input;
*/
Routing\Filter::register(require APP_PATH.'filters'.EXT);
list($uri, $method) = array(Request::uri()->get(), Request::method());
$request = IoC::container()->core('request');
Request::$route = IoC::container()->core('routing.router')->route($method, $uri);
$request->route = IoC::container()->core('routing.router')->route($request);
if ( ! is_null(Request::$route))
if ( ! is_null($request->route))
{
$response = Request::$route->call();
$response = $request->route->call();
}
else
{