From f6ea2676f397c3673150246c0b5654404c153d1b Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 15 Jun 2011 12:41:35 -0700 Subject: [PATCH] Added Input::filled, Input::had, and Input::was_filled. --- system/input.php | 69 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 11 deletions(-) diff --git a/system/input.php b/system/input.php index 513ca658..91b7862a 100644 --- a/system/input.php +++ b/system/input.php @@ -10,14 +10,39 @@ class Input { public static $input; /** - * Determine if the input data contains an item. + * Determine if the input data contains an item or set of items. * - * @param string $key * @return bool */ - public static function has($key) + public static function has() { - return ( ! is_null(static::get($key))); + foreach (func_get_args() as $key) + { + if (is_null(static::get($key))) + { + return false; + } + } + + return true; + } + + /** + * Determine if the input data contains an item or set of items that are not empty. + * + * @return bool + */ + public static function filled() + { + foreach (func_get_args() as $key) + { + if ( ! static::has($key) or trim((string) static::get($key)) == '') + { + return false; + } + } + + return true; } /** @@ -29,9 +54,6 @@ public static function has($key) */ public static function get($key = null, $default = null) { - // ----------------------------------------------------- - // Has the input data been hydrated for the request? - // ----------------------------------------------------- if (is_null(static::$input)) { static::hydrate(); @@ -41,14 +63,39 @@ public static function get($key = null, $default = null) } /** - * Determine if the old input data contains an item. + * Determine if the old input data contains an item or set of items. * - * @param string $key * @return bool */ - public static function has_old($key) + public static function had() { - return ( ! is_null(static::old($key))); + foreach (func_get_args() as $key) + { + if (is_null(static::old($key))) + { + return false; + } + } + + return true; + } + + /** + * Determine if the old input data contains an item or set of items that are not empty. + * + * @return bool + */ + public static function was_filled() + { + foreach (func_get_args() as $key) + { + if ( ! static::had($key) or trim((string) static::old($key)) == '') + { + return false; + } + } + + return true; } /**