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