Passed
Push — feature/typo3v12 ( 16f027...8cdf3c )
by Christian
14:04
created

AbstractExceptionHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 3
rs 10
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 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
    {
54
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
55
    }
56
57
    /**
58
     * handle HTTP-Status-Codes of type 2xx
59
     */
60
    public function handle200(): bool
61
    {
62
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
63
    }
64
65
    public function handle201(): bool
66
    {
67
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
68
    }
69
70
    public function handle202(): bool
71
    {
72
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
73
    }
74
75
    public function handle203(): bool
76
    {
77
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
78
    }
79
80
    public function handle204(): bool
81
    {
82
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
83
    }
84
85
    public function handle205(): bool
86
    {
87
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
88
    }
89
90
    public function handle206(): bool
91
    {
92
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
93
    }
94
95
    public function handle207(): bool
96
    {
97
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
98
    }
99
100
    public function handle208(): bool
101
    {
102
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
103
    }
104
105
    public function handle226(): bool
106
    {
107
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
108
    }
109
110
    /**
111
     * handle HTTP-Status-Codes of type 3xx
112
     */
113
    public function handle300(): bool
114
    {
115
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
116
    }
117
118
    public function handle301(): bool
119
    {
120
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
121
    }
122
123
    public function handle302(): bool
124
    {
125
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
126
    }
127
128
    public function handle303(): bool
129
    {
130
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
131
    }
132
133
    public function handle304(): bool
134
    {
135
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
136
    }
137
138
    public function handle305(): bool
139
    {
140
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
141
    }
142
143
    public function handle306(): bool
144
    {
145
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
146
    }
147
148
    public function handle307(): bool
149
    {
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
    }
157
158
    /**
159
     * handle HTTP-Status-Codes of type 4xx
160
     */
161
    public function handle400(): bool
162
    {
163
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
164
    }
165
166
    public function handle401(): bool
167
    {
168
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
169
    }
170
171
    public function handle402(): bool
172
    {
173
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
174
    }
175
176
    public function handle403(): bool
177
    {
178
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
179
    }
180
181
    public function handle404(): bool
182
    {
183
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
184
    }
185
186
    public function handle405(): bool
187
    {
188
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
189
    }
190
191
    public function handle406(): bool
192
    {
193
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
194
    }
195
196
    public function handle407(): bool
197
    {
198
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
199
    }
200
201
    public function handle408(): bool
202
    {
203
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
204
    }
205
206
    public function handle409(): bool
207
    {
208
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
209
    }
210
211
    public function handle410(): bool
212
    {
213
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
214
    }
215
216
    public function handle411(): bool
217
    {
218
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
219
    }
220
221
    public function handle412(): bool
222
    {
223
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
224
    }
225
226
    public function handle413(): bool
227
    {
228
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
229
    }
230
231
    public function handle414(): bool
232
    {
233
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
234
    }
235
236
    public function handle415(): bool
237
    {
238
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
239
    }
240
241
    public function handle416(): bool
242
    {
243
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
244
    }
245
246
    public function handle417(): bool
247
    {
248
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
249
    }
250
251
    public function handle418(): bool
252
    {
253
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
254
    }
255
256
    public function handle420(): bool
257
    {
258
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
259
    }
260
261
    public function handle421(): bool
262
    {
263
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
264
    }
265
266
    public function handle422(): bool
267
    {
268
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
269
    }
270
271
    public function handle423(): bool
272
    {
273
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
274
    }
275
276
    public function handle424(): bool
277
    {
278
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
279
    }
280
281
    public function handle425(): bool
282
    {
283
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
284
    }
285
286
    public function handle426(): bool
287
    {
288
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
289
    }
290
291
    public function handle428(): bool
292
    {
293
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
294
    }
295
296
    public function handle429(): bool
297
    {
298
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
299
    }
300
301
    public function handle430(): bool
302
    {
303
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
304
    }
305
306
    public function handle431(): bool
307
    {
308
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
309
    }
310
311
    public function handle444(): bool
312
    {
313
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
314
    }
315
316
    public function handle449(): bool
317
    {
318
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
319
    }
320
321
    public function handle451(): bool
322
    {
323
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
324
    }
325
326
    /**
327
     * handle HTTP-Status-Codes of type 5xx
328
     */
329
    public function handle500(): bool
330
    {
331
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
332
    }
333
334
    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
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
342
    }
343
344
    public function handle503(): bool
345
    {
346
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
347
    }
348
349
    public function handle504(): bool
350
    {
351
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
352
    }
353
354
    public function handle505(): bool
355
    {
356
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
357
    }
358
359
    public function handle506(): bool
360
    {
361
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
362
    }
363
364
    public function handle507(): bool
365
    {
366
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
367
    }
368
369
    public function handle508(): bool
370
    {
371
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
372
    }
373
374
    public function handle509(): bool
375
    {
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