From 319c450f6f91a666689fd2948ca4401e3c30444d Mon Sep 17 00:00:00 2001 From: Colin Viebrock Date: Wed, 9 May 2012 15:51:16 -0500 Subject: [PATCH] Make Input::only() and Input::except() into array_only() and array_except() helpers. Signed-off-by: Colin Viebrock --- laravel/helpers.php | 24 ++++++++++++++++++++++++ laravel/input.php | 6 +++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/laravel/helpers.php b/laravel/helpers.php index 392fda12..db5ff436 100644 --- a/laravel/helpers.php +++ b/laravel/helpers.php @@ -245,6 +245,30 @@ function array_pluck($array, $key) }, $array); } +/** + * Get a subset of the items from the given array. + * + * @param array $array + * @param array $keys + * @return array + */ +function array_only($array, $keys) +{ + return array_intersect_key( $array, array_flip((array) $keys) ); +} + +/** + * Get all of the given array except for a specified array of items. + * + * @param array $array + * @param array $keys + * @return array + */ +function array_except($array, $keys) +{ + return array_diff_key( $array, array_flip((array) $keys) ); +} + /** * Transform Eloquent models to a JSON object. * diff --git a/laravel/input.php b/laravel/input.php index 9635b793..6a28b17f 100644 --- a/laravel/input.php +++ b/laravel/input.php @@ -127,7 +127,7 @@ public static function json() */ public static function only($keys) { - return array_intersect_key(static::get(), array_flip((array) $keys)); + return array_only(static::get(), $keys); } /** @@ -146,7 +146,7 @@ public static function only($keys) */ public static function except($keys) { - return array_diff_key(static::get(), array_flip((array) $keys)); + return array_except(static::get(), $keys); } /** @@ -207,7 +207,7 @@ public static function has_file($key) { return ! is_null(static::file("{$key}.tmp_name")); } - + /** * Move an uploaded file to permanent storage. *