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