From d802ae838678713df55931b0a1758260e9fc6f4a Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 16 Jun 2011 22:25:57 -0500 Subject: [PATCH] added arr class and tweaked input class. --- system/arr.php | 23 +++++++++++++++ system/inflector.php | 24 ---------------- system/input.php | 67 +++++--------------------------------------- 3 files changed, 30 insertions(+), 84 deletions(-) create mode 100644 system/arr.php diff --git a/system/arr.php b/system/arr.php new file mode 100644 index 00000000..e59a7301 --- /dev/null +++ b/system/arr.php @@ -0,0 +1,23 @@ + $irregular) { $pattern = '/'.$pattern.'$/i'; @@ -150,9 +141,6 @@ public static function plural($value) } } - // ----------------------------------------------------- - // Check the plural forms for matches. - // ----------------------------------------------------- foreach (static::$plural as $pattern => $plural) { if (preg_match($pattern, $value)) @@ -172,25 +160,16 @@ public static function plural($value) */ public static function singular($value) { - // ----------------------------------------------------- - // If we have already singularized this word, return it. - // ----------------------------------------------------- if (array_key_exists($value, static::$singular_cache)) { return static::$singular_cache[$value]; } - // ----------------------------------------------------- - // Are the singular and plural forms the same? - // ----------------------------------------------------- if (in_array(Str::lower($value), static::$uncountable)) { return static::$singular_cache[$value] = $value; } - // ----------------------------------------------------- - // Is the plural form irregular? - // ----------------------------------------------------- foreach (static::$irregular as $irregular => $pattern) { $pattern = '/'.$pattern.'$/i'; @@ -201,9 +180,6 @@ public static function singular($value) } } - // ----------------------------------------------------- - // Check the singular forms for matches. - // ----------------------------------------------------- foreach (static::$singular as $pattern => $singular) { if (preg_match($pattern, $value)) diff --git a/system/input.php b/system/input.php index 91b7862a..eb98dcac 100644 --- a/system/input.php +++ b/system/input.php @@ -10,7 +10,7 @@ class Input { public static $input; /** - * Determine if the input data contains an item or set of items. + * Determine if the input data contains an item or set of items that are not empty. * * @return bool */ @@ -18,25 +18,7 @@ public static function has() { 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)) == '') + if (is_null(static::get($key)) or trim((string) static::get($key)) == '') { return false; } @@ -59,11 +41,12 @@ public static function get($key = null, $default = null) static::hydrate(); } - return static::from_array(static::$input, $key, $default); + return Arr::get($key, $default, static::$input); } /** - * Determine if the old input data contains an item or set of items. + * Determine if the old input data contains an item or set of + * items that are not empty. * * @return bool */ @@ -71,25 +54,7 @@ public static function had() { 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)) == '') + if (is_null(static::old($key)) or trim((string) static::old($key)) == '') { return false; } @@ -112,25 +77,7 @@ public static function old($key = null, $default = null) throw new \Exception("Sessions must be enabled to retrieve old input data."); } - return static::from_array(Session::get('laravel_old_input', array()), $key, $default); - } - - /** - * Get an item from an array. If no key is specified, the entire array will be returned. - * - * @param array $array - * @param string $key - * @param mixed $default - * @return string - */ - private static function from_array($array, $key, $default) - { - if (is_null($key)) - { - return $array; - } - - return (array_key_exists($key, $array)) ? $array[$key] : $default; + return Arr::get($key, $default, Session::get('laravel_old_input', array())); } /**