From f492c81aa864f8e739b178c1408fa75df2702bb9 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 22 Nov 2011 19:06:56 -0600 Subject: [PATCH] added ability to filter flashed input data. --- laravel/input.php | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/laravel/input.php b/laravel/input.php index 9c723fde..8c826588 100644 --- a/laravel/input.php +++ b/laravel/input.php @@ -66,11 +66,40 @@ public static function get($key = null, $default = null) /** * 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. + * + * + * // Flash all of the input data 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')); + * + * * @return void */ public static function flash($filter = null, $items = array()) { - IoC::core('session')->flash(Input::old_input, static::get()); + $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); } /**