overall code refactoring.

This commit is contained in:
Taylor Otwell
2011-06-14 17:27:11 -05:00
parent af24e8db45
commit 30c83f265d
36 changed files with 720 additions and 559 deletions

View File

@@ -20,17 +20,6 @@ class Input {
return ( ! is_null(static::get($key)));
}
/**
* Determine if the old input data contains an item.
*
* @param string $key
* @return bool
*/
public static function has_old($key)
{
return ( ! is_null(static::old($key)));
}
/**
* Get an item from the input data.
*
@@ -40,10 +29,28 @@ class Input {
*/
public static function get($key = null, $default = null)
{
static::hydrate();
// -----------------------------------------------------
// Has the input data been hydrated for the request?
// -----------------------------------------------------
if (is_null(static::$input))
{
static::hydrate();
}
return static::from_array(static::$input, $key, $default);
}
/**
* Determine if the old input data contains an item.
*
* @param string $key
* @return bool
*/
public static function has_old($key)
{
return ( ! is_null(static::old($key)));
}
/**
* Get input data from the previous request.
*
@@ -86,39 +93,36 @@ class Input {
*/
public static function hydrate()
{
if (is_null(static::$input))
switch (Request::method())
{
switch (Request::method())
{
case 'GET':
static::$input =& $_GET;
break;
case 'GET':
static::$input =& $_GET;
break;
case 'POST':
case 'POST':
static::$input =& $_POST;
break;
case 'PUT':
case 'DELETE':
// ----------------------------------------------------------------------
// Typically, browsers do not support PUT and DELETE methods on HTML
// forms. So, we simulate them using a hidden POST variable.
//
// If the request method is being "spoofed", we'll move the POST array
// into the PUT / DELETE array.
// ----------------------------------------------------------------------
if (isset($_POST['request_method']) and ($_POST['request_method'] == 'PUT' or $_POST['request_method'] == 'DELETE'))
{
static::$input =& $_POST;
break;
case 'PUT':
case 'DELETE':
// ----------------------------------------------------------------------
// Typically, browsers do not support PUT and DELETE methods on HTML
// forms. So, we simulate them using a hidden POST variable.
//
// If the request method is being "spoofed", we'll move the POST array
// into the PUT / DELETE array.
// ----------------------------------------------------------------------
if (isset($_POST['request_method']) and ($_POST['request_method'] == 'PUT' or $_POST['request_method'] == 'DELETE'))
{
static::$input =& $_POST;
}
// ----------------------------------------------------------------------
// If the request is a true PUT request, read the php://input file.
// ----------------------------------------------------------------------
else
{
parse_str(file_get_contents('php://input'), static::$input);
}
}
}
// ----------------------------------------------------------------------
// If the request is a true PUT request, read the php://input file.
// ----------------------------------------------------------------------
else
{
parse_str(file_get_contents('php://input'), static::$input);
}
}
}