2011-06-08 23:45:08 -05:00
|
|
|
<?php namespace System;
|
|
|
|
|
|
|
|
|
|
class Input {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The input data for the request.
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
public static $input;
|
|
|
|
|
|
2011-07-12 20:04:14 -05:00
|
|
|
/**
|
|
|
|
|
* Get all of the input data for the request.
|
|
|
|
|
*
|
|
|
|
|
* This method returns a merged array containing Input::get and Input::file.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public static function all()
|
|
|
|
|
{
|
|
|
|
|
return array_merge(static::get(), static::file());
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-15 12:41:35 -07:00
|
|
|
/**
|
2011-06-17 12:23:26 -05:00
|
|
|
* Determine if the input data contains an item.
|
2011-06-08 23:45:08 -05:00
|
|
|
*
|
2011-06-16 22:45:33 -05:00
|
|
|
* @param string $key
|
2011-06-08 23:45:08 -05:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2011-06-16 22:45:33 -05:00
|
|
|
public static function has($key)
|
2011-06-08 23:45:08 -05:00
|
|
|
{
|
2011-06-17 11:16:45 -07:00
|
|
|
return ( ! is_null(static::get($key)) and trim((string) static::get($key)) !== '');
|
2011-06-08 23:45:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2011-06-14 17:27:11 -05:00
|
|
|
* Get an item from the input data.
|
2011-06-08 23:45:08 -05:00
|
|
|
*
|
|
|
|
|
* @param string $key
|
2011-06-14 17:27:11 -05:00
|
|
|
* @param mixed $default
|
|
|
|
|
* @return string
|
2011-06-08 23:45:08 -05:00
|
|
|
*/
|
2011-06-14 17:27:11 -05:00
|
|
|
public static function get($key = null, $default = null)
|
2011-06-08 23:45:08 -05:00
|
|
|
{
|
2011-06-14 17:27:11 -05:00
|
|
|
if (is_null(static::$input))
|
|
|
|
|
{
|
|
|
|
|
static::hydrate();
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-07 22:30:15 -05:00
|
|
|
return Arr::get(static::$input, $key, $default);
|
2011-06-08 23:45:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2011-06-17 12:23:26 -05:00
|
|
|
* Determine if the old input data contains an item.
|
2011-06-15 12:41:35 -07:00
|
|
|
*
|
2011-06-16 22:45:33 -05:00
|
|
|
* @param string $key
|
2011-06-15 12:41:35 -07:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2011-06-16 22:45:33 -05:00
|
|
|
public static function had($key)
|
2011-06-15 12:41:35 -07:00
|
|
|
{
|
2011-06-17 11:16:45 -07:00
|
|
|
return ( ! is_null(static::old($key)) and trim((string) static::old($key)) !== '');
|
2011-06-08 23:45:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get input data from the previous request.
|
|
|
|
|
*
|
|
|
|
|
* @param string $key
|
|
|
|
|
* @param mixed $default
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public static function old($key = null, $default = null)
|
|
|
|
|
{
|
|
|
|
|
if (Config::get('session.driver') == '')
|
|
|
|
|
{
|
|
|
|
|
throw new \Exception("Sessions must be enabled to retrieve old input data.");
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-07 22:30:15 -05:00
|
|
|
return Arr::get(Session::get('laravel_old_input', array()), $key, $default);
|
2011-06-08 23:45:08 -05:00
|
|
|
}
|
|
|
|
|
|
2011-06-26 08:44:31 -05:00
|
|
|
/**
|
|
|
|
|
* Get an item from the uploaded file data.
|
|
|
|
|
*
|
|
|
|
|
* @param string $key
|
|
|
|
|
* @param mixed $default
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2011-06-26 09:10:11 -05:00
|
|
|
public static function file($key = null, $default = null)
|
2011-06-26 08:44:31 -05:00
|
|
|
{
|
2011-07-07 22:30:15 -05:00
|
|
|
return Arr::get($_FILES, $key, $default);
|
2011-06-26 08:44:31 -05:00
|
|
|
}
|
|
|
|
|
|
2011-06-08 23:45:08 -05:00
|
|
|
/**
|
|
|
|
|
* Hydrate the input data for the request.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public static function hydrate()
|
|
|
|
|
{
|
2011-06-14 17:27:11 -05:00
|
|
|
switch (Request::method())
|
2011-06-08 23:45:08 -05:00
|
|
|
{
|
2011-06-14 17:27:11 -05:00
|
|
|
case 'GET':
|
|
|
|
|
static::$input =& $_GET;
|
|
|
|
|
break;
|
2011-06-08 23:45:08 -05:00
|
|
|
|
2011-06-14 17:27:11 -05:00
|
|
|
case 'POST':
|
|
|
|
|
static::$input =& $_POST;
|
|
|
|
|
break;
|
2011-06-08 23:45:08 -05:00
|
|
|
|
2011-06-14 17:27:11 -05:00
|
|
|
case 'PUT':
|
|
|
|
|
case 'DELETE':
|
2011-07-08 12:41:03 -07:00
|
|
|
if (Request::spoofed())
|
2011-06-14 17:27:11 -05:00
|
|
|
{
|
|
|
|
|
static::$input =& $_POST;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
parse_str(file_get_contents('php://input'), static::$input);
|
|
|
|
|
}
|
2011-06-08 23:45:08 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|