-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredirect.php
187 lines (170 loc) · 4.53 KB
/
redirect.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php namespace Laravel; use Laravel\Routing\Router;
class Redirect extends Response {
/**
* Create a redirect response to application root.
*
* @param int $status
* @param bool $https
* @return Redirect
*/
public static function home($status = 302, $https = null)
{
return static::to(URL::home($https), $status);
}
/**
* Create a redirect response to the HTTP referrer.
*
* @param int $status
* @return Redirect
*/
public static function back($status = 302)
{
return static::to(Request::referrer(), $status);
}
/**
* Create a redirect response.
*
* <code>
* // Create a redirect response to a location within the application
* return Redirect::to('user/profile');
*
* // Create a redirect response with a 301 status code
* return Redirect::to('user/profile', 301);
* </code>
*
* @param string $url
* @param int $status
* @param bool $https
* @return Redirect
*/
public static function to($url, $status = 302, $https = null)
{
return static::make('', $status)->header('Location', URL::to($url, $https));
}
/**
* Create a redirect response to a HTTPS URL.
*
* @param string $url
* @param int $status
* @return Redirect
*/
public static function to_secure($url, $status = 302)
{
return static::to($url, $status, true);
}
/**
* Create a redirect response to a controller action.
*
* @param string $action
* @param array $parameters
* @param int $status
* @return Redirect
*/
public static function to_action($action, $parameters = array(), $status = 302)
{
return static::to(URL::to_action($action, $parameters), $status);
}
/**
* Create a redirect response to a named route.
*
* <code>
* // Create a redirect response to the "login" named route
* return Redirect::to_route('login');
*
* // Create a redirect response to the "profile" named route with parameters
* return Redirect::to_route('profile', array($username));
* </code>
*
* @param string $route
* @param array $parameters
* @param int $status
* @return Redirect
*/
public static function to_route($route, $parameters = array(), $status = 302)
{
return static::to(URL::to_route($route, $parameters), $status);
}
/**
* Add an item to the session flash data.
*
* This is useful for "passing" status messages or other data to the next request.
*
* <code>
* // Create a redirect response and flash to the session
* return Redirect::to('profile')->with('message', 'Welcome Back!');
* </code>
*
* @param string $key
* @param mixed $value
* @return Redirect
*/
public function with($key, $value)
{
if (Config::get('session.driver') == '')
{
throw new \Exception('A session driver must be set before setting flash data.');
}
Session::flash($key, $value);
return $this;
}
/**
* Flash the old input to the session and return the Redirect instance.
*
* 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;
}
/**
* Flash a Validator's errors to the session data.
*
* This method allows you to conveniently pass validation errors back to views.
*
* <code>
* // Redirect and flash validator errors the session
* return Redirect::to('register')->with_errors($validator);
* </code>
*
* @param Validator|Messages $container
* @return Redirect
*/
public function with_errors($container)
{
$errors = ($container instanceof Validator) ? $container->errors : $container;
return $this->with('errors', $errors);
}
/**
* Send the headers and content of the response to the browser.
*
* @return void
*/
public function send()
{
// Dump all output buffering, this ensures
// that symphony will send our redirect headers
// properly if we've outputted any content from
// within Laravel.
while (ob_get_level() > 0)
{
ob_end_clean();
}
return parent::send();
}
}