refactoring various classes.

This commit is contained in:
Taylor Otwell
2011-11-22 18:00:17 -06:00
parent 246434f4c7
commit 5f348b2c6e
14 changed files with 373 additions and 210 deletions

View File

@@ -64,6 +64,34 @@ class Redirect extends Response {
return $this;
}
/**
* Flash the old input to the session and return the Redirect instance.
*
* This method has the same signature as the Input::flash method, it just provides
* a convenient method of flashing the input and return the Redirect in one line.
* Once the input has been flashed, it can be retrieved via the Input::old method.
*
* <code>
* // Redirect and flash all of the input data to the session
* return Redirect::to_login()->with_input();
*
* // Redirect and flash only a few of the input items
* return Redirect::to_login()->with_input('only', array('email', 'username'));
*
* // Redirect and flash all but a few of the input items
* return Redirect::to_login()->with_input('except', array('password', 'ssn'));
* </code>
*
* @param string $filter
* @param array $items
* @return Redirect
*/
public function with_input($filter = null, $items = array())
{
Input::flash($filter, $items);
return $this;
}
/**
* Magic Method to handle creation of redirects to named routes.
*
@@ -73,22 +101,28 @@ class Redirect extends Response {
*
* // Create a redirect response to a named route using HTTPS
* return Redirect::to_secure_profile();
*
* // Create a redirect response to a named route with wildcard parameters
* return Redirect::to_profile(array($username));
* </code>
*/
public static function __callStatic($method, $parameters)
{
// Extract the parameters that should be placed in the URL. These parameters
// are used to fill all of the wildcard slots in the route URI definition.
// They are passed as the first parameter to this magic method.
$wildcards = (isset($parameters[0])) ? $parameters[0] : array();
$status = (isset($parameters[1])) ? $parameters[1] : 302;
$parameters = (isset($parameters[0])) ? $parameters[0] : array();
if (strpos($method, 'to_secure_') === 0)
{
return static::to(URL::to_route(substr($method, 10), $parameters, true), $status);
return static::to(URL::to_route(substr($method, 10), $wildcards, true), $status);
}
if (strpos($method, 'to_') === 0)
{
return static::to(URL::to_route(substr($method, 3), $parameters), $status);
return static::to(URL::to_route(substr($method, 3), $wildcards), $status);
}
throw new \BadMethodCallException("Method [$method] is not defined on the Redirect class.");