1
|
|
|
<?php namespace Neomerx\JsonApi\Http; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2015 [email protected] (www.neomerx.com) |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
use \Closure; |
20
|
|
|
use \LogicException; |
21
|
|
|
use \Psr\Http\Message\UriInterface; |
22
|
|
|
use \Psr\Http\Message\StreamInterface; |
23
|
|
|
use \Psr\Http\Message\ServerRequestInterface; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @package Neomerx\JsonApi |
27
|
|
|
*/ |
28
|
|
|
class Request implements ServerRequestInterface |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var Closure |
32
|
|
|
*/ |
33
|
|
|
private $getHeaderClosure; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var Closure |
37
|
|
|
*/ |
38
|
|
|
private $getQueryParamsClosure; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param Closure $getHeaderClosure |
42
|
|
|
* @param Closure $getQueryParamsClosure |
43
|
|
|
*/ |
44
|
18 |
|
public function __construct(Closure $getHeaderClosure, Closure $getQueryParamsClosure) |
|
|
|
|
45
|
|
|
{ |
46
|
18 |
|
$this->getHeaderClosure = $getHeaderClosure; |
47
|
18 |
|
$this->getQueryParamsClosure = $getQueryParamsClosure; |
48
|
18 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @inheritdoc |
52
|
|
|
*/ |
53
|
17 |
|
public function getHeader($name) |
54
|
|
|
{ |
55
|
17 |
|
$closure = $this->getHeaderClosure; |
56
|
17 |
|
$result = $closure($name); |
57
|
|
|
|
58
|
17 |
|
return $result; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @inheritdoc |
63
|
|
|
*/ |
64
|
15 |
|
public function getQueryParams() |
65
|
|
|
{ |
66
|
15 |
|
$closure = $this->getQueryParamsClosure; |
67
|
15 |
|
$result = $closure(); |
68
|
|
|
|
69
|
15 |
|
return $result; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @inheritdoc |
74
|
|
|
*/ |
75
|
1 |
|
public function getProtocolVersion() |
76
|
|
|
{ |
77
|
|
|
// Method is not used. |
78
|
1 |
|
throw new LogicException(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @inheritdoc |
83
|
|
|
*/ |
84
|
1 |
|
public function withProtocolVersion($version) |
85
|
|
|
{ |
86
|
|
|
// Method is not used. |
87
|
1 |
|
throw new LogicException(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @inheritdoc |
92
|
|
|
*/ |
93
|
1 |
|
public function getHeaders() |
94
|
|
|
{ |
95
|
|
|
// Method is not used. |
96
|
1 |
|
throw new LogicException(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @inheritdoc |
101
|
|
|
*/ |
102
|
1 |
|
public function hasHeader($name) |
103
|
|
|
{ |
104
|
|
|
// Method is not used. |
105
|
1 |
|
throw new LogicException(); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @inheritdoc |
110
|
|
|
*/ |
111
|
1 |
|
public function getHeaderLine($name) |
112
|
|
|
{ |
113
|
|
|
// Method is not used. |
114
|
1 |
|
throw new LogicException(); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @inheritdoc |
119
|
|
|
*/ |
120
|
1 |
|
public function withHeader($name, $value) |
121
|
|
|
{ |
122
|
|
|
// Method is not used. |
123
|
1 |
|
throw new LogicException(); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @inheritdoc |
128
|
|
|
*/ |
129
|
1 |
|
public function withAddedHeader($name, $value) |
130
|
|
|
{ |
131
|
|
|
// Method is not used. |
132
|
1 |
|
throw new LogicException(); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @inheritdoc |
137
|
|
|
*/ |
138
|
1 |
|
public function withoutHeader($name) |
139
|
|
|
{ |
140
|
|
|
// Method is not used. |
141
|
1 |
|
throw new LogicException(); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @inheritdoc |
146
|
|
|
*/ |
147
|
1 |
|
public function getBody() |
148
|
|
|
{ |
149
|
|
|
// Method is not used. |
150
|
1 |
|
throw new LogicException(); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @inheritdoc |
155
|
|
|
*/ |
156
|
1 |
|
public function withBody(StreamInterface $body) |
157
|
|
|
{ |
158
|
|
|
// Method is not used. |
159
|
1 |
|
throw new LogicException(); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @inheritdoc |
164
|
|
|
*/ |
165
|
1 |
|
public function getRequestTarget() |
166
|
|
|
{ |
167
|
|
|
// Method is not used. |
168
|
1 |
|
throw new LogicException(); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @inheritdoc |
173
|
|
|
*/ |
174
|
1 |
|
public function withRequestTarget($requestTarget) |
175
|
|
|
{ |
176
|
|
|
// Method is not used. |
177
|
1 |
|
throw new LogicException(); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @inheritdoc |
182
|
|
|
*/ |
183
|
1 |
|
public function getMethod() |
184
|
|
|
{ |
185
|
|
|
// Method is not used. |
186
|
1 |
|
throw new LogicException(); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @inheritdoc |
191
|
|
|
*/ |
192
|
1 |
|
public function withMethod($method) |
193
|
|
|
{ |
194
|
|
|
// Method is not used. |
195
|
1 |
|
throw new LogicException(); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @inheritdoc |
200
|
|
|
*/ |
201
|
1 |
|
public function getUri() |
202
|
|
|
{ |
203
|
|
|
// Method is not used. |
204
|
1 |
|
throw new LogicException(); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @inheritdoc |
209
|
|
|
*/ |
210
|
1 |
|
public function withUri(UriInterface $uri, $preserveHost = false) |
211
|
|
|
{ |
212
|
|
|
// Method is not used. |
213
|
1 |
|
throw new LogicException(); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* @inheritdoc |
218
|
|
|
*/ |
219
|
1 |
|
public function getServerParams() |
220
|
|
|
{ |
221
|
|
|
// Method is not used. |
222
|
1 |
|
throw new LogicException(); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* @inheritdoc |
227
|
|
|
*/ |
228
|
1 |
|
public function getCookieParams() |
229
|
|
|
{ |
230
|
|
|
// Method is not used. |
231
|
1 |
|
throw new LogicException(); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* @inheritdoc |
236
|
|
|
*/ |
237
|
1 |
|
public function withCookieParams(array $cookies) |
238
|
|
|
{ |
239
|
|
|
// Method is not used. |
240
|
1 |
|
throw new LogicException(); |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* @inheritdoc |
245
|
|
|
*/ |
246
|
1 |
|
public function withQueryParams(array $query) |
247
|
|
|
{ |
248
|
|
|
// Method is not used. |
249
|
1 |
|
throw new LogicException(); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* @inheritdoc |
254
|
|
|
*/ |
255
|
1 |
|
public function getUploadedFiles() |
256
|
|
|
{ |
257
|
|
|
// Method is not used. |
258
|
1 |
|
throw new LogicException(); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* @inheritdoc |
263
|
|
|
*/ |
264
|
1 |
|
public function withUploadedFiles(array $uploadedFiles) |
265
|
|
|
{ |
266
|
|
|
// Method is not used. |
267
|
1 |
|
throw new LogicException(); |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* @inheritdoc |
272
|
|
|
*/ |
273
|
1 |
|
public function getParsedBody() |
274
|
|
|
{ |
275
|
|
|
// Method is not used. |
276
|
1 |
|
throw new LogicException(); |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* @inheritdoc |
281
|
|
|
*/ |
282
|
1 |
|
public function withParsedBody($data) |
283
|
|
|
{ |
284
|
|
|
// Method is not used. |
285
|
1 |
|
throw new LogicException(); |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* @inheritdoc |
290
|
|
|
*/ |
291
|
1 |
|
public function getAttributes() |
292
|
|
|
{ |
293
|
|
|
// Method is not used. |
294
|
1 |
|
throw new LogicException(); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* @inheritdoc |
299
|
|
|
*/ |
300
|
1 |
|
public function getAttribute($name, $default = null) |
301
|
|
|
{ |
302
|
|
|
// Method is not used. |
303
|
1 |
|
throw new LogicException(); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* @inheritdoc |
308
|
|
|
*/ |
309
|
1 |
|
public function withAttribute($name, $value) |
310
|
|
|
{ |
311
|
|
|
// Method is not used. |
312
|
1 |
|
throw new LogicException(); |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* @inheritdoc |
317
|
|
|
*/ |
318
|
1 |
|
public function withoutAttribute($name) |
319
|
|
|
{ |
320
|
|
|
// Method is not used. |
321
|
1 |
|
throw new LogicException(); |
322
|
|
|
} |
323
|
|
|
} |
324
|
|
|
|
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.