1
|
|
|
<?php |
2
|
|
|
namespace Aoe\Restler\System\Restler; |
3
|
|
|
|
4
|
|
|
/*************************************************************** |
5
|
|
|
* Copyright notice |
6
|
|
|
* |
7
|
|
|
* (c) 2015 AOE GmbH <[email protected]> |
8
|
|
|
* |
9
|
|
|
* All rights reserved |
10
|
|
|
* |
11
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
12
|
|
|
* free software; you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU General Public License as published by |
14
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
15
|
|
|
* (at your option) any later version. |
16
|
|
|
* |
17
|
|
|
* The GNU General Public License can be found at |
18
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
19
|
|
|
* |
20
|
|
|
* This script is distributed in the hope that it will be useful, |
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23
|
|
|
* GNU General Public License for more details. |
24
|
|
|
* |
25
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
26
|
|
|
***************************************************************/ |
27
|
|
|
|
28
|
|
|
use Aoe\Restler\Configuration\ExtensionConfiguration; |
29
|
|
|
use Luracast\Restler\RestException; |
30
|
|
|
use Luracast\Restler\Restler; |
31
|
|
|
use Luracast\Restler\Scope; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* This abstract class can be used to call ONE central method, |
35
|
|
|
* which handles ALL exceptions (the current HTTP-Status-Code doesn't matter)! |
36
|
|
|
* |
37
|
|
|
* @package Restler |
38
|
|
|
*/ |
39
|
|
|
abstract class AbstractExceptionHandler |
40
|
|
|
{ |
41
|
|
|
/** |
42
|
|
|
* This object can be used, to check the Extension-Configuration (maybe we want to |
43
|
|
|
* handle an exception in different ways - based on the Extension-Configuration) |
44
|
|
|
* |
45
|
|
|
* @var ExtensionConfiguration |
46
|
|
|
*/ |
47
|
|
|
protected $extensionConfiguration; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param ExtensionConfiguration $extensionConfiguration |
51
|
|
|
*/ |
52
|
|
|
public function __construct(ExtensionConfiguration $extensionConfiguration) |
53
|
|
|
{ |
54
|
|
|
$this->extensionConfiguration = $extensionConfiguration; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* handle HTTP-Status-Codes of type 1xx |
60
|
|
|
*/ |
61
|
1 |
|
public function handle100() |
62
|
|
|
{ |
63
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
64
|
|
|
} |
65
|
1 |
|
public function handle101() |
66
|
|
|
{ |
67
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
68
|
|
|
} |
69
|
1 |
|
public function handle102() |
70
|
|
|
{ |
71
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* handle HTTP-Status-Codes of type 2xx |
77
|
|
|
*/ |
78
|
1 |
|
public function handle200() |
79
|
|
|
{ |
80
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
81
|
|
|
} |
82
|
1 |
|
public function handle201() |
83
|
|
|
{ |
84
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
85
|
|
|
} |
86
|
1 |
|
public function handle202() |
87
|
|
|
{ |
88
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
89
|
|
|
} |
90
|
1 |
|
public function handle203() |
91
|
|
|
{ |
92
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
93
|
|
|
} |
94
|
1 |
|
public function handle204() |
95
|
|
|
{ |
96
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
97
|
|
|
} |
98
|
1 |
|
public function handle205() |
99
|
|
|
{ |
100
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
101
|
|
|
} |
102
|
1 |
|
public function handle206() |
103
|
|
|
{ |
104
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
105
|
|
|
} |
106
|
1 |
|
public function handle207() |
107
|
|
|
{ |
108
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
109
|
|
|
} |
110
|
1 |
|
public function handle208() |
111
|
|
|
{ |
112
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
113
|
|
|
} |
114
|
1 |
|
public function handle226() |
115
|
|
|
{ |
116
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* handle HTTP-Status-Codes of type 3xx |
122
|
|
|
*/ |
123
|
1 |
|
public function handle300() |
124
|
|
|
{ |
125
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
126
|
|
|
} |
127
|
1 |
|
public function handle301() |
128
|
|
|
{ |
129
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
130
|
|
|
} |
131
|
1 |
|
public function handle302() |
132
|
|
|
{ |
133
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
134
|
|
|
} |
135
|
1 |
|
public function handle303() |
136
|
|
|
{ |
137
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
138
|
|
|
} |
139
|
1 |
|
public function handle304() |
140
|
|
|
{ |
141
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
142
|
|
|
} |
143
|
1 |
|
public function handle305() |
144
|
|
|
{ |
145
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
146
|
|
|
} |
147
|
1 |
|
public function handle306() |
148
|
|
|
{ |
149
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
150
|
|
|
} |
151
|
1 |
|
public function handle307() |
152
|
|
|
{ |
153
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
154
|
|
|
} |
155
|
1 |
|
public function handle308() |
156
|
|
|
{ |
157
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* handle HTTP-Status-Codes of type 4xx |
163
|
|
|
*/ |
164
|
1 |
|
public function handle400() |
165
|
|
|
{ |
166
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
167
|
|
|
} |
168
|
1 |
|
public function handle401() |
169
|
|
|
{ |
170
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
171
|
|
|
} |
172
|
1 |
|
public function handle402() |
173
|
|
|
{ |
174
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
175
|
|
|
} |
176
|
1 |
|
public function handle403() |
177
|
|
|
{ |
178
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
179
|
|
|
} |
180
|
1 |
|
public function handle404() |
181
|
|
|
{ |
182
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
183
|
|
|
} |
184
|
1 |
|
public function handle405() |
185
|
|
|
{ |
186
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
187
|
|
|
} |
188
|
1 |
|
public function handle406() |
189
|
|
|
{ |
190
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
191
|
|
|
} |
192
|
1 |
|
public function handle407() |
193
|
|
|
{ |
194
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
195
|
|
|
} |
196
|
1 |
|
public function handle408() |
197
|
|
|
{ |
198
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
199
|
|
|
} |
200
|
1 |
|
public function handle409() |
201
|
|
|
{ |
202
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
203
|
|
|
} |
204
|
1 |
|
public function handle410() |
205
|
|
|
{ |
206
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
207
|
|
|
} |
208
|
1 |
|
public function handle411() |
209
|
|
|
{ |
210
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
211
|
|
|
} |
212
|
1 |
|
public function handle412() |
213
|
|
|
{ |
214
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
215
|
|
|
} |
216
|
1 |
|
public function handle413() |
217
|
|
|
{ |
218
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
219
|
|
|
} |
220
|
1 |
|
public function handle414() |
221
|
|
|
{ |
222
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
223
|
|
|
} |
224
|
1 |
|
public function handle415() |
225
|
|
|
{ |
226
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
227
|
|
|
} |
228
|
1 |
|
public function handle416() |
229
|
|
|
{ |
230
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
231
|
|
|
} |
232
|
1 |
|
public function handle417() |
233
|
|
|
{ |
234
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
235
|
|
|
} |
236
|
1 |
|
public function handle418() |
237
|
|
|
{ |
238
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
239
|
|
|
} |
240
|
1 |
|
public function handle420() |
241
|
|
|
{ |
242
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
243
|
|
|
} |
244
|
1 |
|
public function handle421() |
245
|
|
|
{ |
246
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
247
|
|
|
} |
248
|
1 |
|
public function handle422() |
249
|
|
|
{ |
250
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
251
|
|
|
} |
252
|
1 |
|
public function handle423() |
253
|
|
|
{ |
254
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
255
|
|
|
} |
256
|
1 |
|
public function handle424() |
257
|
|
|
{ |
258
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
259
|
|
|
} |
260
|
1 |
|
public function handle425() |
261
|
|
|
{ |
262
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
263
|
|
|
} |
264
|
1 |
|
public function handle426() |
265
|
|
|
{ |
266
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
267
|
|
|
} |
268
|
1 |
|
public function handle428() |
269
|
|
|
{ |
270
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
271
|
|
|
} |
272
|
1 |
|
public function handle429() |
273
|
|
|
{ |
274
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
275
|
|
|
} |
276
|
1 |
|
public function handle430() |
277
|
|
|
{ |
278
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
279
|
|
|
} |
280
|
1 |
|
public function handle431() |
281
|
|
|
{ |
282
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
283
|
|
|
} |
284
|
1 |
|
public function handle444() |
285
|
|
|
{ |
286
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
287
|
|
|
} |
288
|
1 |
|
public function handle449() |
289
|
|
|
{ |
290
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
291
|
|
|
} |
292
|
1 |
|
public function handle451() |
293
|
|
|
{ |
294
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* handle HTTP-Status-Codes of type 5xx |
299
|
|
|
*/ |
300
|
1 |
|
public function handle500() |
301
|
|
|
{ |
302
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
303
|
|
|
} |
304
|
1 |
|
public function handle501() |
305
|
|
|
{ |
306
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
307
|
|
|
} |
308
|
1 |
|
public function handle502() |
309
|
|
|
{ |
310
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
311
|
|
|
} |
312
|
1 |
|
public function handle503() |
313
|
|
|
{ |
314
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
315
|
|
|
} |
316
|
1 |
|
public function handle504() |
317
|
|
|
{ |
318
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
319
|
|
|
} |
320
|
1 |
|
public function handle505() |
321
|
|
|
{ |
322
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
323
|
|
|
} |
324
|
1 |
|
public function handle506() |
325
|
|
|
{ |
326
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
327
|
|
|
} |
328
|
1 |
|
public function handle507() |
329
|
|
|
{ |
330
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
331
|
|
|
} |
332
|
1 |
|
public function handle508() |
333
|
|
|
{ |
334
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
335
|
|
|
} |
336
|
1 |
|
public function handle509() |
337
|
|
|
{ |
338
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
339
|
|
|
} |
340
|
1 |
|
public function handle510() |
341
|
|
|
{ |
342
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* handle HTTP-Status-Codes of type 9xx |
348
|
|
|
*/ |
349
|
1 |
|
public function handle900() |
350
|
|
|
{ |
351
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
352
|
|
|
} |
353
|
1 |
|
public function handle901() |
354
|
|
|
{ |
355
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
356
|
|
|
} |
357
|
1 |
|
public function handle902() |
358
|
|
|
{ |
359
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
360
|
|
|
} |
361
|
1 |
|
public function handle903() |
362
|
|
|
{ |
363
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
364
|
|
|
} |
365
|
1 |
|
public function handle904() |
366
|
|
|
{ |
367
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
368
|
|
|
} |
369
|
1 |
|
public function handle905() |
370
|
|
|
{ |
371
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
372
|
|
|
} |
373
|
1 |
|
public function handle906() |
374
|
|
|
{ |
375
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
376
|
|
|
} |
377
|
1 |
|
public function handle907() |
378
|
|
|
{ |
379
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
380
|
|
|
} |
381
|
1 |
|
public function handle950() |
382
|
|
|
{ |
383
|
1 |
|
return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* This is the right place, where we can handle exceptions, which were thrown in REST-API's! |
388
|
|
|
* |
389
|
|
|
* The return value (boolean) describes, if restler should display an error as output: |
390
|
|
|
* TRUE means: restler should NOT display an error as output (so, we must do that) |
391
|
|
|
* FALSE means: restler should dislay an error as output |
392
|
|
|
* |
393
|
|
|
* @param RestException $exception |
394
|
|
|
* @param Restler $restler |
395
|
|
|
* @return boolean |
396
|
|
|
*/ |
397
|
|
|
abstract protected function handleException(RestException $exception, Restler $restler); |
398
|
|
|
|
399
|
|
|
/** |
400
|
|
|
* This method must be protected - otherwise we can't test this class in unittests |
401
|
|
|
* |
402
|
|
|
* @return Restler |
403
|
|
|
*/ |
404
|
|
|
protected function getRestler() |
405
|
|
|
{ |
406
|
|
|
return Scope::get('Restler'); |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
/** |
410
|
|
|
* This method must be protected - otherwise we can't test this class in unittests |
411
|
|
|
* |
412
|
|
|
* @param array $exceptionHandlerArgs |
413
|
|
|
* @return RestException |
414
|
|
|
*/ |
415
|
|
|
protected function getRestlerException(array $exceptionHandlerArgs = []) |
416
|
|
|
{ |
417
|
|
|
if (count($exceptionHandlerArgs) > 0 && $exceptionHandlerArgs[0] instanceof RestException) { |
418
|
|
|
return $exceptionHandlerArgs[0]; |
419
|
|
|
} |
420
|
|
|
return $this->getRestler()->exception; |
421
|
|
|
} |
422
|
|
|
} |
423
|
|
|
|