-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathRedirectResponse.php
executable file
·258 lines (224 loc) · 5.81 KB
/
RedirectResponse.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<?php
namespace Illuminate\Http;
use Illuminate\Contracts\Support\MessageProvider;
use Illuminate\Session\Store as SessionStore;
use Illuminate\Support\MessageBag;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\ForwardsCalls;
use Illuminate\Support\Traits\Macroable;
use Illuminate\Support\ViewErrorBag;
use Symfony\Component\HttpFoundation\File\UploadedFile as SymfonyUploadedFile;
use Symfony\Component\HttpFoundation\RedirectResponse as BaseRedirectResponse;
class RedirectResponse extends BaseRedirectResponse
{
use ForwardsCalls, ResponseTrait, Macroable {
Macroable::__call as macroCall;
}
/**
* The request instance.
*
* @var \Illuminate\Http\Request
*/
protected $request;
/**
* The session store instance.
*
* @var \Illuminate\Session\Store
*/
protected $session;
/**
* Flash a piece of data to the session.
*
* @param string|array $key
* @param mixed $value
* @return $this
*/
public function with($key, $value = null)
{
$key = is_array($key) ? $key : [$key => $value];
foreach ($key as $k => $v) {
$this->session->flash($k, $v);
}
return $this;
}
/**
* Add multiple cookies to the response.
*
* @param array $cookies
* @return $this
*/
public function withCookies(array $cookies)
{
foreach ($cookies as $cookie) {
$this->headers->setCookie($cookie);
}
return $this;
}
/**
* Flash an array of input to the session.
*
* @param array|null $input
* @return $this
*/
public function withInput(?array $input = null)
{
$this->session->flashInput($this->removeFilesFromInput(
! is_null($input) ? $input : $this->request->input()
));
return $this;
}
/**
* Remove all uploaded files form the given input array.
*
* @param array $input
* @return array
*/
protected function removeFilesFromInput(array $input)
{
foreach ($input as $key => $value) {
if (is_array($value)) {
$input[$key] = $this->removeFilesFromInput($value);
}
if ($value instanceof SymfonyUploadedFile) {
unset($input[$key]);
}
}
return $input;
}
/**
* Flash an array of input to the session.
*
* @return $this
*/
public function onlyInput()
{
return $this->withInput($this->request->only(func_get_args()));
}
/**
* Flash an array of input to the session.
*
* @return $this
*/
public function exceptInput()
{
return $this->withInput($this->request->except(func_get_args()));
}
/**
* Flash a container of errors to the session.
*
* @param \Illuminate\Contracts\Support\MessageProvider|array|string $provider
* @param string $key
* @return $this
*/
public function withErrors($provider, $key = 'default')
{
$value = $this->parseErrors($provider);
$errors = $this->session->get('errors', new ViewErrorBag);
if (! $errors instanceof ViewErrorBag) {
$errors = new ViewErrorBag;
}
$this->session->flash(
'errors', $errors->put($key, $value)
);
return $this;
}
/**
* Parse the given errors into an appropriate value.
*
* @param \Illuminate\Contracts\Support\MessageProvider|array|string $provider
* @return \Illuminate\Support\MessageBag
*/
protected function parseErrors($provider)
{
if ($provider instanceof MessageProvider) {
return $provider->getMessageBag();
}
return new MessageBag((array) $provider);
}
/**
* Add a fragment identifier to the URL.
*
* @param string $fragment
* @return $this
*/
public function withFragment($fragment)
{
return $this->withoutFragment()
->setTargetUrl($this->getTargetUrl().'#'.Str::after($fragment, '#'));
}
/**
* Remove any fragment identifier from the response URL.
*
* @return $this
*/
public function withoutFragment()
{
return $this->setTargetUrl(Str::before($this->getTargetUrl(), '#'));
}
/**
* Get the original response content.
*
* @return null
*/
public function getOriginalContent()
{
//
}
/**
* Get the request instance.
*
* @return \Illuminate\Http\Request|null
*/
public function getRequest()
{
return $this->request;
}
/**
* Set the request instance.
*
* @param \Illuminate\Http\Request $request
* @return void
*/
public function setRequest(Request $request)
{
$this->request = $request;
}
/**
* Get the session store instance.
*
* @return \Illuminate\Session\Store|null
*/
public function getSession()
{
return $this->session;
}
/**
* Set the session store instance.
*
* @param \Illuminate\Session\Store $session
* @return void
*/
public function setSession(SessionStore $session)
{
$this->session = $session;
}
/**
* Dynamically bind flash data in the session.
*
* @param string $method
* @param array $parameters
* @return mixed
*
* @throws \BadMethodCallException
*/
public function __call($method, $parameters)
{
if (static::hasMacro($method)) {
return $this->macroCall($method, $parameters);
}
if (str_starts_with($method, 'with')) {
return $this->with(Str::snake(substr($method, 4)), $parameters[0]);
}
static::throwBadMethodCallException($method);
}
}