1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace W2w\Lib\Apie\Plugins\Core\ObjectAccess; |
5
|
|
|
|
6
|
|
|
use ReflectionClass; |
7
|
|
|
use W2w\Lib\Apie\Plugins\Core\ObjectAccess\Getters\CodeGetter; |
8
|
|
|
use W2w\Lib\Apie\Plugins\Core\ObjectAccess\Getters\ErrorsGetter; |
9
|
|
|
use W2w\Lib\Apie\Plugins\Core\ObjectAccess\Getters\MessageGetter; |
10
|
|
|
use W2w\Lib\ApieObjectAccessNormalizer\Exceptions\ValidationException; |
11
|
|
|
use W2w\Lib\ApieObjectAccessNormalizer\ObjectAccess\ObjectAccess; |
12
|
|
|
|
13
|
|
|
class ExceptionObjectAccess extends ObjectAccess |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var bool |
17
|
|
|
*/ |
18
|
|
|
private $debug; |
19
|
|
|
|
20
|
|
|
public function __construct(bool $debug) |
21
|
|
|
{ |
22
|
|
|
$this->debug = $debug; |
23
|
|
|
parent::__construct(true, true); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Excepions are always immutable. |
28
|
|
|
* |
29
|
|
|
* @param ReflectionClass $reflectionClass |
30
|
|
|
* @return array |
31
|
|
|
*/ |
32
|
|
|
protected function getSetterMapping(ReflectionClass $reflectionClass): array |
33
|
|
|
{ |
34
|
|
|
return []; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
protected function getGetterMapping(ReflectionClass $reflectionClass): array |
38
|
|
|
{ |
39
|
|
|
$mapping = parent::getGetterMapping($reflectionClass); |
40
|
|
|
$mapping['message'] = [new MessageGetter()]; |
41
|
|
|
$mapping['code'] = [new CodeGetter()]; |
42
|
|
|
unset($mapping['file']); |
43
|
|
|
unset($mapping['line']); |
44
|
|
|
unset($mapping['previous']); |
45
|
|
|
if ($this->debug) { |
46
|
|
|
$mapping['trace'] = $mapping['traceAsString']; |
47
|
|
|
} else { |
48
|
|
|
unset($mapping['trace']); |
49
|
|
|
} |
50
|
|
|
unset($mapping['traceAsString']); |
51
|
|
|
if ($reflectionClass->name === ValidationException::class) { |
52
|
|
|
$mapping['errors'] = [new ErrorsGetter()]; |
53
|
|
|
unset($mapping['exceptions']); |
54
|
|
|
unset($mapping['i18n']); |
55
|
|
|
unset($mapping['errorBag']); |
56
|
|
|
unset($mapping['headers']); |
57
|
|
|
unset($mapping['statusCode']); |
58
|
|
|
} |
59
|
|
|
return $mapping; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|