merged skunkworks into develop.
This commit is contained in:
@@ -17,9 +17,7 @@ class Input {
|
||||
const old_input = 'laravel_old_input';
|
||||
|
||||
/**
|
||||
* Get all of the input data for the request.
|
||||
*
|
||||
* This method returns a merged array containing Input::get() and Input::files().
|
||||
* Get all of the input data for the request, including files.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -31,7 +29,7 @@ class Input {
|
||||
/**
|
||||
* Determine if the input data contains an item.
|
||||
*
|
||||
* If the item is in the input array, but is an empty string, false will be returned.
|
||||
* If the input item is an empty string, false will be returned.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
@@ -44,7 +42,7 @@ class Input {
|
||||
/**
|
||||
* Get an item from the input data.
|
||||
*
|
||||
* This method should be used for all request methods (GET, POST, PUT, and DELETE).
|
||||
* This method is used for all request verbs (GET, POST, PUT, and DELETE).
|
||||
*
|
||||
* <code>
|
||||
* // Get the "email" item from the input array
|
||||
@@ -60,56 +58,45 @@ class Input {
|
||||
*/
|
||||
public static function get($key = null, $default = null)
|
||||
{
|
||||
return Arr::get(static::$input, $key, $default);
|
||||
return array_get(static::$input, $key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flash the input for the current request to the session.
|
||||
*
|
||||
* The input data to be flashed may be controlled by using a filter and an array
|
||||
* of included or excluded input data. This provides a convenient way of keeping
|
||||
* sensitive information like passwords out of the session.
|
||||
* Get a subset of the items from the input data.
|
||||
*
|
||||
* <code>
|
||||
* // Flash all of the input data to the session
|
||||
* Input::flash();
|
||||
* // Get only the email from the input data
|
||||
* $value = Input::only('email');
|
||||
*
|
||||
* // Flash only a few input items to the session
|
||||
* Input::flash('only', array('name', 'email'));
|
||||
*
|
||||
* // Flash all but a few input items to the session
|
||||
* Input::flash('except', array('password'));
|
||||
* // Get only the username and email from the input data
|
||||
* $input = Input::only(array('username', 'email'));
|
||||
* </code>
|
||||
*
|
||||
* @return void
|
||||
* @param array $keys
|
||||
* @return array
|
||||
*/
|
||||
public static function flash($filter = null, $items = array())
|
||||
public static function only($keys)
|
||||
{
|
||||
$flash = static::get();
|
||||
|
||||
// Since the items flashed to the session can be filtered, we will iterate
|
||||
// all of the input data and either remove or include the input item based
|
||||
// on the specified filter and array of items to be flashed.
|
||||
if ($filter == 'only')
|
||||
{
|
||||
$flash = array_intersect_key($flash, array_flip($items));
|
||||
}
|
||||
elseif ($filter == 'except')
|
||||
{
|
||||
$flash = array_diff_key($flash, array_flip($items));
|
||||
}
|
||||
|
||||
IoC::core('session')->flash(Input::old_input, $flash);
|
||||
return array_intersect_key(static::get(), array_flip((array) $keys));
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush the old input from the session.
|
||||
* Get all of the input data except for a specified array of items.
|
||||
*
|
||||
* @return void
|
||||
* <code>
|
||||
* // Get all of the input data except for username
|
||||
* $input = Input::except('username');
|
||||
*
|
||||
* // Get all of the input data except for username and email
|
||||
* $input = Input::except(array('username', 'email'));
|
||||
* </code>
|
||||
*
|
||||
* @param array $keys
|
||||
* @return array
|
||||
*/
|
||||
public static function flush()
|
||||
public static function except($keys)
|
||||
{
|
||||
IoC::core('session')->flash(Input::old_input, array());
|
||||
return array_diff_key(static::get(), array_flip($keys));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,9 +127,7 @@ class Input {
|
||||
*/
|
||||
public static function old($key = null, $default = null)
|
||||
{
|
||||
$old = IoC::core('session')->get(Input::old_input, array());
|
||||
|
||||
return Arr::get($old, $key, $default);
|
||||
return array_get(Session::get(Input::old_input, array()), $key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,7 +137,7 @@ class Input {
|
||||
* // Get the array of information for the "picture" upload
|
||||
* $picture = Input::file('picture');
|
||||
*
|
||||
* // Get a specific element from the file array
|
||||
* // Get a specific element from within the file's data array
|
||||
* $size = Input::file('picture.size');
|
||||
* </code>
|
||||
*
|
||||
@@ -162,7 +147,7 @@ class Input {
|
||||
*/
|
||||
public static function file($key = null, $default = null)
|
||||
{
|
||||
return Arr::get($_FILES, $key, $default);
|
||||
return array_get($_FILES, $key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,8 +156,8 @@ class Input {
|
||||
* This method is simply a convenient wrapper around move_uploaded_file.
|
||||
*
|
||||
* <code>
|
||||
* // Move the "picture" item from the $_FILES array to a permanent location
|
||||
* Input::upload('picture', 'path/to/storage/picture.jpg');
|
||||
* // Move the "picture" file to a permanent location on disk
|
||||
* Input::upload('picture', 'path/to/photos/picture.jpg');
|
||||
* </code>
|
||||
*
|
||||
* @param string $key
|
||||
@@ -181,7 +166,44 @@ class Input {
|
||||
*/
|
||||
public static function upload($key, $path)
|
||||
{
|
||||
return File::upload($key, $path);
|
||||
if (is_null(static::file($key))) return false;
|
||||
|
||||
return move_uploaded_file(static::file("{$key}.tmp_name"), $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flash the input for the current request to the session.
|
||||
*
|
||||
* <code>
|
||||
* // Flash all of the input to the session
|
||||
* Input::flash();
|
||||
*
|
||||
* // Flash only a few input items to the session
|
||||
* Input::flash('only', array('name', 'email'));
|
||||
*
|
||||
* // Flash all but a few input items to the session
|
||||
* Input::flash('except', array('password', 'social_number'));
|
||||
* </code>
|
||||
*
|
||||
* @param string $filter
|
||||
* @param array $keys
|
||||
* @return void
|
||||
*/
|
||||
public static function flash($filter = null, $keys = array())
|
||||
{
|
||||
$flash = ( ! is_null($filter)) ? static::$filter($keys) : static::get();
|
||||
|
||||
Session::flash(Input::old_input, $flash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush all of the old input from the session.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function flush()
|
||||
{
|
||||
Session::flash(Input::old_input, array());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user