* // Get the "email" item from the input array * $email = Input::get('email'); * * // Return a default value if the specified item doesn't exist * $email = Input::get('name', 'Taylor'); * * * @param string $key * @param mixed $default * @return mixed */ public static function get($key = null, $default = null) { $input = Request::foundation()->request->all(); if (is_null($key)) { return array_merge($input, static::query()); } $value = array_get($input, $key); if (is_null($value)) { return array_get(static::query(), $key, $default); } return $value; } /** * Get an item from the query string. * * * // Get the "email" item from the query string * $email = Input::query('email'); * * // Return a default value if the specified item doesn't exist * $email = Input::query('name', 'Taylor'); * * * @param string $key * @param mixed $default * @return mixed */ public static function query($key = null, $default = null) { return array_get(Request::foundation()->query->all(), $key, $default); } /** * Get the JSON payload for the request. * * @return object */ public static function json() { if ( ! is_null(static::$json)) return static::$json; return static::$json = json_decode(Request::foundation()->getContent()); } /** * Get a subset of the items from the input data. * * * // Get only the email from the input data * $value = Input::only('email'); * * // Get only the username and email from the input data * $input = Input::only(array('username', 'email')); * * * @param array $keys * @return array */ public static function only($keys) { return array_only(static::get(), $keys); } /** * Get all of the input data except for a specified array of items. * * * // 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')); * * * @param array $keys * @return array */ public static function except($keys) { return array_except(static::get(), $keys); } /** * Determine if the old input data contains an item. * * @param string $key * @return bool */ public static function had($key) { return trim((string) static::old($key)) !== ''; } /** * Get input data from the previous request. * * * // Get the "email" item from the old input * $email = Input::old('email'); * * // Return a default value if the specified item doesn't exist * $email = Input::old('name', 'Taylor'); * * * @param string $key * @param mixed $default * @return string */ public static function old($key = null, $default = null) { return array_get(Session::get(Input::old_input, array()), $key, $default); } /** * Get an item from the uploaded file data. * * * // Get the array of information for the "picture" upload * $picture = Input::file('picture'); * * * @param string $key * @param mixed $default * @return UploadedFile */ public static function file($key = null, $default = null) { return array_get($_FILES, $key, $default); } /** * Determine if the uploaded data contains a file. * * @param string $key * @return bool */ public static function has_file($key) { return strlen(static::file("{$key}.tmp_name", "")) > 0; } /** * Move an uploaded file to permanent storage. * * This method is simply a convenient wrapper around move_uploaded_file. * * * // Move the "picture" file to a new permanent location on disk * Input::upload('picture', 'path/to/photos', 'picture.jpg'); * * * @param string $key * @param string $directory * @param string $name * @return bool */ public static function upload($key, $directory, $name = null) { if (is_null(static::file($key))) return false; return Request::foundation()->files->get($key)->move($directory, $name); } /** * Flash the input for the current request to the session. * * * // 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')); * * * @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()); } /** * Merge new input into the current request's input array. * * @param array $input * @return void */ public static function merge(array $input) { Request::foundation()->request->add($input); } /** * Replace the input for the current request. * * @param array $input * @return void */ public static function replace(array $input) { Request::foundation()->request->replace($input); } /** * Clear the input for the current request. * @return void */ public static function clear() { Request::foundation()->request->replace(array()); } }