1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php namespace System;
- class Redirect {
-
- public $response;
-
- public function __construct($response)
- {
- $this->response = $response;
- }
-
- public static function to($url, $method = 'location', $status = 302, $https = false)
- {
- $url = URL::to($url, $https);
- return ($method == 'refresh')
- ? new static(Response::make('', $status)->header('Refresh', '0;url='.$url))
- : new static(Response::make('', $status)->header('Location', $url));
- }
-
- public static function to_secure($url, $method = 'location', $status = 302)
- {
- return static::to($url, $method, $status, true);
- }
-
- public function with($key, $value)
- {
- if (Config::get('session.driver') == '')
- {
- throw new \Exception("Attempting to flash data to the session, but no session driver has been specified.");
- }
- Session::flash($key, $value);
- return $this;
- }
-
- public static function __callStatic($method, $parameters)
- {
- $parameters = (isset($parameters[0])) ? $parameters[0] : array();
-
- if (strpos($method, 'to_secure_') === 0)
- {
- return static::to(URL::to_route(substr($method, 10), $parameters, true));
- }
-
- if (strpos($method, 'to_') === 0)
- {
- return static::to(URL::to_route(substr($method, 3), $parameters));
- }
- throw new \Exception("Method [$method] is not defined on the Redirect class.");
- }
- }
|