reverting di refactoring.
This commit is contained in:
parent
f5680e4537
commit
ef9e4dfd61
|
@ -146,13 +146,13 @@
|
|||
'Hasher' => 'Laravel\\Security\\Hasher',
|
||||
'HTML' => 'Laravel\\HTML',
|
||||
'Inflector' => 'Laravel\\Inflector',
|
||||
'Input' => 'Laravel\\Facades\\Input',
|
||||
'Input' => 'Laravel\\Input',
|
||||
'IoC' => 'Laravel\\IoC',
|
||||
'Lang' => 'Laravel\\Lang',
|
||||
'URL' => 'Laravel\\URL',
|
||||
'Redirect' => 'Laravel\\Redirect',
|
||||
'Redis' => 'Laravel\\Redis',
|
||||
'Request' => 'Laravel\\Facades\\Request',
|
||||
'Request' => 'Laravel\\Request',
|
||||
'Response' => 'Laravel\\Response',
|
||||
'Session' => 'Laravel\\Session\\Manager',
|
||||
'Str' => 'Laravel\\Str',
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
*/
|
||||
require SYS_PATH.'arr'.EXT;
|
||||
require SYS_PATH.'config'.EXT;
|
||||
require SYS_PATH.'facades'.EXT;
|
||||
|
||||
/**
|
||||
* Load some core configuration files by default so we don't have to
|
||||
|
|
|
@ -2,69 +2,6 @@
|
|||
|
||||
return array(
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Various Laravel Components
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Many of the Laravel classes are resolved through the inversion of control
|
||||
| container to maintain a high level of testability and flexibility.
|
||||
|
|
||||
| Most of them are also accessible through a "Facade", which simulates the
|
||||
| class being usable via static methods for convenience. Facades allow the
|
||||
| framework to keep a convenient API, while still having a testable core.
|
||||
|
|
||||
*/
|
||||
|
||||
'laravel.input' => array('singleton' => true, 'resolver' => function($c)
|
||||
{
|
||||
require SYS_PATH.'input'.EXT;
|
||||
|
||||
$input = array();
|
||||
|
||||
$request = $c->core('request');
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
return new Input($input, $_FILES);
|
||||
}),
|
||||
|
||||
|
||||
'laravel.request' => array('singleton' => true, 'resolver' => function($c)
|
||||
{
|
||||
require_once SYS_PATH.'request'.EXT;
|
||||
|
||||
return new Request($c->core('uri'), $_POST, $_SERVER);
|
||||
}),
|
||||
|
||||
|
||||
'laravel.uri' => array('singleton' => true, 'resolver' => function($c)
|
||||
{
|
||||
require_once SYS_PATH.'uri'.EXT;
|
||||
|
||||
return new URI($_SERVER);
|
||||
}),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Laravel Routing Components
|
||||
|
|
|
@ -82,9 +82,7 @@ protected static function method($method)
|
|||
*/
|
||||
protected static function action($action, $https)
|
||||
{
|
||||
$request = IoC::container()->core('uri');
|
||||
|
||||
return HTML::entities(URL::to(((is_null($action)) ? $uri->get() : $action), $https));
|
||||
return HTML::entities(URL::to(((is_null($action)) ? Request::uri()->get() : $action), $https));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,14 +7,7 @@ class Input {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $input;
|
||||
|
||||
/**
|
||||
* The $_FILES array for the request.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $files;
|
||||
public static $input;
|
||||
|
||||
/**
|
||||
* The key used to store old input in the session.
|
||||
|
@ -23,19 +16,6 @@ class Input {
|
|||
*/
|
||||
const old_input = 'laravel_old_input';
|
||||
|
||||
/**
|
||||
* Create a new instance of the Input manager.
|
||||
*
|
||||
* @param array $input
|
||||
* @param array $files
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($input, $files)
|
||||
{
|
||||
$this->input = $input;
|
||||
$this->files = $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the input data for the request.
|
||||
*
|
||||
|
@ -43,9 +23,9 @@ public function __construct($input, $files)
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function all()
|
||||
public static function all()
|
||||
{
|
||||
return array_merge($this->get(), $this->file());
|
||||
return array_merge(static::get(), static::file());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -56,9 +36,9 @@ public function all()
|
|||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function has($key)
|
||||
public static function has($key)
|
||||
{
|
||||
return ( ! is_null($this->get($key)) and trim((string) $this->get($key)) !== '');
|
||||
return ( ! is_null(static::get($key)) and trim((string) static::get($key)) !== '');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -78,9 +58,9 @@ public function has($key)
|
|||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key = null, $default = null)
|
||||
public static function get($key = null, $default = null)
|
||||
{
|
||||
return Arr::get($this->input, $key, $default);
|
||||
return Arr::get(static::$input, $key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,9 +69,9 @@ public function get($key = null, $default = null)
|
|||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function had($key)
|
||||
public static function had($key)
|
||||
{
|
||||
return ( ! is_null($this->old($key)) and trim((string) $this->old($key)) !== '');
|
||||
return ( ! is_null(static::old($key)) and trim((string) static::old($key)) !== '');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -109,7 +89,7 @@ public function had($key)
|
|||
* @param mixed $default
|
||||
* @return string
|
||||
*/
|
||||
public function old($key = null, $default = null)
|
||||
public static function old($key = null, $default = null)
|
||||
{
|
||||
if (Config::get('session.driver') == '')
|
||||
{
|
||||
|
@ -134,9 +114,9 @@ public function old($key = null, $default = null)
|
|||
* @param mixed $default
|
||||
* @return array
|
||||
*/
|
||||
public function file($key = null, $default = null)
|
||||
public static function file($key = null, $default = null)
|
||||
{
|
||||
return Arr::get($this->files, $key, $default);
|
||||
return Arr::get($_FILES, $key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -153,9 +133,9 @@ public function file($key = null, $default = null)
|
|||
* @param string $path
|
||||
* @return bool
|
||||
*/
|
||||
public function upload($key, $path)
|
||||
public static function upload($key, $path)
|
||||
{
|
||||
return array_key_exists($key, $this->files) ? File::upload($key, $path, $this->files) : false;
|
||||
return array_key_exists($key, $_FILES) ? File::upload($key, $path, $_FILES) : false;
|
||||
}
|
||||
|
||||
}
|
|
@ -37,12 +37,52 @@
|
|||
* 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
|
||||
|
@ -51,13 +91,13 @@
|
|||
*/
|
||||
Routing\Filter::register(require APP_PATH.'filters'.EXT);
|
||||
|
||||
$request = IoC::container()->core('request');
|
||||
list($uri, $method) = array(Request::uri()->get(), Request::method());
|
||||
|
||||
$request->route = IoC::container()->core('routing.router')->route($request);
|
||||
Request::$route = IoC::container()->core('routing.router')->route($method, $uri);
|
||||
|
||||
if ( ! is_null($request->route))
|
||||
if ( ! is_null(Request::$route))
|
||||
{
|
||||
$response = $request->route->call();
|
||||
$response = Request::$route->call();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -105,7 +105,7 @@ public static function make($results, $total, $per_page)
|
|||
*/
|
||||
public static function page($total, $per_page)
|
||||
{
|
||||
$page = IoC::container()->core('input')->get('page', 1);
|
||||
$page = Input::get('page', 1);
|
||||
|
||||
// The page will be validated and adjusted if it is less than one or greater
|
||||
// than the last page. For example, if the current page is not an integer or
|
||||
|
@ -250,11 +250,11 @@ protected function element($element, $text, $page, $disabler)
|
|||
// We will assume the page links should use HTTPS if the current request
|
||||
// is also using HTTPS. Since pagination links automatically point to
|
||||
// the current URI, this makes pretty good sense.
|
||||
$request = IoC::container()->core('request');
|
||||
list($uri, $secure) = array(Request::uri()->get(), Request::secure());
|
||||
|
||||
$appendage = $this->appendage($element, $page);
|
||||
|
||||
return HTML::link($request->uri().$appendage, $text, array('class' => $class), $requst->secure());
|
||||
return HTML::link($uri.$appendage, $text, array('class' => $class), $secure);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,33 +2,19 @@
|
|||
|
||||
class Request {
|
||||
|
||||
/**
|
||||
* The route handling the current request.
|
||||
*
|
||||
* @var Routing\Route
|
||||
*/
|
||||
public $route;
|
||||
|
||||
/**
|
||||
* The request URI for the current request.
|
||||
*
|
||||
* @var URI
|
||||
*/
|
||||
protected $uri;
|
||||
public static $uri;
|
||||
|
||||
/**
|
||||
* The $_POST array for the request.
|
||||
* The route handling the current request.
|
||||
*
|
||||
* @var array
|
||||
* @var Routing\Route
|
||||
*/
|
||||
protected $post;
|
||||
|
||||
/**
|
||||
* The $_SERVER array for the request.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $server;
|
||||
public static $route;
|
||||
|
||||
/**
|
||||
* The request data key that is used to indicate a spoofed request method.
|
||||
|
@ -38,28 +24,13 @@ class Request {
|
|||
const spoofer = '__spoofer';
|
||||
|
||||
/**
|
||||
* Create a new Request instance.
|
||||
* Get the URI instance for the current request.
|
||||
*
|
||||
* @param URI $uri
|
||||
* @param array $post
|
||||
* @param array $server
|
||||
* @return void
|
||||
* @return URI
|
||||
*/
|
||||
public function __construct($uri, $post, $server)
|
||||
public static function uri()
|
||||
{
|
||||
$this->uri = $uri;
|
||||
$this->post = $post;
|
||||
$this->server = $server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current request's URI.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function uri()
|
||||
{
|
||||
return $this->uri->get();
|
||||
return (is_null(static::$uri)) ? static::$uri = new URI($_SERVER) : static::$uri;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -71,9 +42,9 @@ public function uri()
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
public function method()
|
||||
public static function method()
|
||||
{
|
||||
return ($this->spoofed()) ? $this->post[Request::spoofer] : $this->server['REQUEST_METHOD'];
|
||||
return (static::spoofed()) ? $_POST[Request::spoofer] : $_SERVER['REQUEST_METHOD'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -85,9 +56,9 @@ public function method()
|
|||
* @param mixed $default
|
||||
* @return string
|
||||
*/
|
||||
public function server($key = null, $default = null)
|
||||
public static function server($key = null, $default = null)
|
||||
{
|
||||
return Arr::get($this->server, strtoupper($key), $default);
|
||||
return Arr::get($_SERVER, strtoupper($key), $default);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -95,9 +66,9 @@ public function server($key = null, $default = null)
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function spoofed()
|
||||
public static function spoofed()
|
||||
{
|
||||
return is_array($this->post) and array_key_exists(Request::spoofer, $this->post);
|
||||
return is_array($_POST) and array_key_exists(Request::spoofer, $_POST);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -106,19 +77,19 @@ public function spoofed()
|
|||
* @param mixed $default
|
||||
* @return string
|
||||
*/
|
||||
public function ip($default = '0.0.0.0')
|
||||
public static function ip($default = '0.0.0.0')
|
||||
{
|
||||
if (isset($this->server['HTTP_X_FORWARDED_FOR']))
|
||||
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
|
||||
{
|
||||
return $this->server['HTTP_X_FORWARDED_FOR'];
|
||||
return $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||
}
|
||||
elseif (isset($this->server['HTTP_CLIENT_IP']))
|
||||
elseif (isset($_SERVER['HTTP_CLIENT_IP']))
|
||||
{
|
||||
return $this->server['HTTP_CLIENT_IP'];
|
||||
return $_SERVER['HTTP_CLIENT_IP'];
|
||||
}
|
||||
elseif (isset($this->server['REMOTE_ADDR']))
|
||||
elseif (isset($_SERVER['REMOTE_ADDR']))
|
||||
{
|
||||
return $this->server['REMOTE_ADDR'];
|
||||
return $_SERVER['REMOTE_ADDR'];
|
||||
}
|
||||
|
||||
return ($default instanceof Closure) ? call_user_func($default) : $default;
|
||||
|
@ -129,9 +100,9 @@ public function ip($default = '0.0.0.0')
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
public function protocol()
|
||||
public static function protocol()
|
||||
{
|
||||
return Arr::get($this->server, 'SERVER_PROTOCOL', 'HTTP/1.1');
|
||||
return Arr::get($_SERVER, 'SERVER_PROTOCOL', 'HTTP/1.1');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -139,9 +110,9 @@ public function protocol()
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function secure()
|
||||
public static function secure()
|
||||
{
|
||||
return isset($this->server['HTTPS']) and strtolower($this->server['HTTPS']) !== 'off';
|
||||
return isset($_SERVER['HTTPS']) and strtolower($_SERVER['HTTPS']) !== 'off';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -149,11 +120,11 @@ public function secure()
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function ajax()
|
||||
public static function ajax()
|
||||
{
|
||||
if ( ! isset($this->server['HTTP_X_REQUESTED_WITH'])) return false;
|
||||
if ( ! isset($_SERVER['HTTP_X_REQUESTED_WITH'])) return false;
|
||||
|
||||
return strtolower($this->server['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest';
|
||||
return strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -161,9 +132,9 @@ public function ajax()
|
|||
*
|
||||
* @return Route
|
||||
*/
|
||||
public function route()
|
||||
public static function route()
|
||||
{
|
||||
return $this->route;
|
||||
return static::$route;
|
||||
}
|
||||
|
||||
}
|
|
@ -261,9 +261,7 @@ public function headers()
|
|||
$this->header('Content-Type', 'text/html; charset='.Config::$items['application']['encoding']);
|
||||
}
|
||||
|
||||
$request = IoC::container()->core('request');
|
||||
|
||||
header($request->protocol().' '.$this->status.' '.$this->statuses[$this->status]);
|
||||
header(Request::protocol().' '.$this->status.' '.$this->statuses[$this->status]);
|
||||
|
||||
foreach ($this->headers as $name => $value)
|
||||
{
|
||||
|
|
|
@ -102,13 +102,12 @@ public function find($name)
|
|||
/**
|
||||
* Search the routes for the route matching a request method and URI.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param string $method
|
||||
* @param string $uri
|
||||
* @return Route
|
||||
*/
|
||||
public function route(Request $request)
|
||||
public function route($method, $uri)
|
||||
{
|
||||
list($method, $uri) = array($request->method(), $request->uri());
|
||||
|
||||
$routes = $this->loader->load($uri);
|
||||
|
||||
// All route URIs begin with the request method and have a leading
|
||||
|
|
|
@ -53,7 +53,7 @@ public static function to_secure($url = '')
|
|||
*/
|
||||
public static function to_asset($url, $https = null)
|
||||
{
|
||||
if (is_null($https)) $https = IoC::container()->core('request')->secure();
|
||||
if (is_null($https)) $https = Request::secure();
|
||||
|
||||
$url = static::to($url, $https);
|
||||
|
||||
|
|
|
@ -341,7 +341,7 @@ protected function size($attribute, $value)
|
|||
{
|
||||
return $this->attributes[$attribute];
|
||||
}
|
||||
elseif (array_key_exists($attribute, IoC::container()->core('input')->file()))
|
||||
elseif (array_key_exists($attribute, Input::file()))
|
||||
{
|
||||
return $value['size'] / 1024;
|
||||
}
|
||||
|
@ -529,9 +529,7 @@ protected function message($attribute, $rule)
|
|||
// type of attribute being validated, either a file or a string.
|
||||
elseif (in_array($rule, $this->size_rules) and ! $this->has_rule($attribute, $this->numeric_rules))
|
||||
{
|
||||
$files = IoC::container()->core('input')->file();
|
||||
|
||||
$line = (array_key_exists($attribute, $files)) ? "file" : "string";
|
||||
$line = (array_key_exists($attribute, Input::file())) ? "file" : "string";
|
||||
|
||||
return Lang::line("validation.{$rule}.{$line}")->get($this->language);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue