refactoring.
This commit is contained in:
@@ -7,7 +7,34 @@ class Input {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $input;
|
||||
protected $input;
|
||||
|
||||
/**
|
||||
* The $_FILES array for the current request.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $files;
|
||||
|
||||
/**
|
||||
* The key used to store old input in the session.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const old_input = 'laravel_old_input';
|
||||
|
||||
/**
|
||||
* Create a new input manager instance.
|
||||
*
|
||||
* @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.
|
||||
@@ -16,9 +43,9 @@ class Input {
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function all()
|
||||
public function all()
|
||||
{
|
||||
return array_merge(static::get(), static::file());
|
||||
return array_merge($this->get(), $this->file());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -27,9 +54,9 @@ class Input {
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public static function has($key)
|
||||
public function has($key)
|
||||
{
|
||||
return ( ! is_null(static::get($key)) and trim((string) static::get($key)) !== '');
|
||||
return ( ! is_null($this->get($key)) and trim((string) $this->get($key)) !== '');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,21 +64,13 @@ class Input {
|
||||
*
|
||||
* This method should be used for all request methods (GET, POST, PUT, and DELETE).
|
||||
*
|
||||
* <code>
|
||||
* // Get an item from the input to the application
|
||||
* $value = Input::get('name');
|
||||
*
|
||||
* // Get an item from the input and return "Fred" if the item doesn't exist
|
||||
* $value = Input::get('name', 'Fred');
|
||||
* </code>
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get($key = null, $default = null)
|
||||
public function get($key = null, $default = null)
|
||||
{
|
||||
return Arr::get(static::$input, $key, $default);
|
||||
return Arr::get($this->input, $key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,27 +79,19 @@ class Input {
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public static function had($key)
|
||||
public function had($key)
|
||||
{
|
||||
return ( ! is_null(static::old($key)) and trim((string) static::old($key)) !== '');
|
||||
return ( ! is_null($this->old($key)) and trim((string) $this->old($key)) !== '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get input data from the previous request.
|
||||
*
|
||||
* <code>
|
||||
* // Get an item from the previous request's input
|
||||
* $value = Input::old('name');
|
||||
*
|
||||
* // Get an item from the previous request's input and return "Fred" if it doesn't exist.
|
||||
* $value = Input::old('name', 'Fred');
|
||||
* </code>
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @return string
|
||||
*/
|
||||
public static function old($key = null, $default = null)
|
||||
public function old($key = null, $default = null)
|
||||
{
|
||||
if (Config::get('session.driver') == '')
|
||||
{
|
||||
@@ -89,29 +100,19 @@ class Input {
|
||||
|
||||
$driver = IoC::container()->resolve('laravel.session');
|
||||
|
||||
return Arr::get($driver->get('laravel_old_input', array()), $key, $default);
|
||||
return Arr::get($driver->get(Input::old_input, array()), $key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item from the uploaded file data.
|
||||
*
|
||||
* "Dot" syntax may be used to get a specific item from the file array.
|
||||
*
|
||||
* <code>
|
||||
* // Get the array of information regarding an uploaded file
|
||||
* $file = Input::file('picture');
|
||||
*
|
||||
* // Get an element from the array of information regarding an uploaded file
|
||||
* $size = Input::file('picture.size');
|
||||
* </code>
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @return array
|
||||
*/
|
||||
public static function file($key = null, $default = null)
|
||||
public function file($key = null, $default = null)
|
||||
{
|
||||
return Arr::get($_FILES, $key, $default);
|
||||
return Arr::get($this->files, $key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,49 +120,13 @@ class Input {
|
||||
*
|
||||
* This method is simply a convenient wrapper around move_uploaded_file.
|
||||
*
|
||||
* <code>
|
||||
* // Move the "picture" file to a permament location on disk
|
||||
* Input::upload('picture', PUBLIC_PATH.'img/picture.jpg');
|
||||
* </code>
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $path
|
||||
* @return bool
|
||||
*/
|
||||
public static function upload($key, $path)
|
||||
public function upload($key, $path)
|
||||
{
|
||||
return array_key_exists($key, $_FILES) ? File::upload($key, $path, $_FILES) : false;
|
||||
return array_key_exists($key, $this->files) ? File::upload($key, $path, $this->files) : false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the input values for the current request.
|
||||
*/
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
unset($input[Request::spoofer]);
|
||||
|
||||
Input::$input = $input;
|
||||
}
|
||||
Reference in New Issue
Block a user