|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Created by PhpStorm. |
|
5
|
|
|
* Project: json-rpc-server |
|
6
|
|
|
* User: sv |
|
7
|
|
|
* Date: 06.02.2021 |
|
8
|
|
|
* Time: 10:45 |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
declare(strict_types=1); |
|
12
|
|
|
|
|
13
|
|
|
namespace Onnov\JsonRpcServer\Definition; |
|
14
|
|
|
|
|
15
|
|
|
use stdClass; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class RpcErrorDefinition |
|
19
|
|
|
* |
|
20
|
|
|
* @package Onnov\JsonRpcServer\Definition |
|
21
|
|
|
*/ |
|
22
|
|
|
class RpcErrorDefinition |
|
23
|
|
|
{ |
|
24
|
|
|
use CastableToArray; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Description of what went wrong. |
|
28
|
|
|
* |
|
29
|
|
|
* @var string|null |
|
30
|
|
|
*/ |
|
31
|
|
|
private $description = null; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Unique error code. |
|
35
|
|
|
* |
|
36
|
|
|
* @var int |
|
37
|
|
|
*/ |
|
38
|
|
|
private $code; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Unique error message. |
|
42
|
|
|
* |
|
43
|
|
|
* @var string |
|
44
|
|
|
*/ |
|
45
|
|
|
private $message; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* SON-Schema of the additional error data. |
|
49
|
|
|
* |
|
50
|
|
|
* @var stdClass|null |
|
51
|
|
|
*/ |
|
52
|
|
|
private $data = null; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Set the logLevel when using the Psr\Log |
|
56
|
|
|
* |
|
57
|
|
|
* @var string|null |
|
58
|
|
|
*/ |
|
59
|
|
|
private $logLevel; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* RpcErrorDefinition constructor. |
|
63
|
|
|
* |
|
64
|
|
|
* @param mixed[] $data |
|
65
|
|
|
*/ |
|
66
|
9 |
|
public function __construct(array $data = []) |
|
67
|
|
|
{ |
|
68
|
9 |
|
if (isset($data['code'])) { |
|
69
|
9 |
|
$this->code = $data['code']; |
|
70
|
|
|
} |
|
71
|
9 |
|
if (isset($data['message'])) { |
|
72
|
9 |
|
$this->message = $data['message']; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
9 |
|
$this->description = $data['description'] ?? null; |
|
76
|
9 |
|
$this->data = $data['data'] ?? null; |
|
77
|
9 |
|
$this->logLevel = $data['logLevel'] ?? null; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @return string|null |
|
82
|
|
|
*/ |
|
83
|
|
|
public function getDescription(): ?string |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->description; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param string|null $description |
|
90
|
|
|
* @return RpcErrorDefinition |
|
91
|
|
|
*/ |
|
92
|
|
|
public function setDescription(?string $description): self |
|
93
|
|
|
{ |
|
94
|
|
|
$this->description = $description; |
|
95
|
|
|
|
|
96
|
|
|
return $this; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @return int |
|
101
|
|
|
*/ |
|
102
|
4 |
|
public function getCode(): int |
|
103
|
|
|
{ |
|
104
|
4 |
|
return $this->code; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @param int $code |
|
109
|
|
|
* @return RpcErrorDefinition |
|
110
|
|
|
*/ |
|
111
|
|
|
public function setCode(int $code): self |
|
112
|
|
|
{ |
|
113
|
|
|
$this->code = $code; |
|
114
|
|
|
|
|
115
|
|
|
return $this; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @return string |
|
120
|
|
|
*/ |
|
121
|
4 |
|
public function getMessage(): string |
|
122
|
|
|
{ |
|
123
|
4 |
|
return $this->message; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @param string $message |
|
128
|
|
|
* @return RpcErrorDefinition |
|
129
|
|
|
*/ |
|
130
|
1 |
|
public function setMessage(string $message): self |
|
131
|
|
|
{ |
|
132
|
1 |
|
$this->message = $message; |
|
133
|
|
|
|
|
134
|
1 |
|
return $this; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @return stdClass|null |
|
139
|
|
|
*/ |
|
140
|
2 |
|
public function getData(): ?stdClass |
|
141
|
|
|
{ |
|
142
|
2 |
|
return $this->data; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* @param stdClass|null $data |
|
147
|
|
|
* @return RpcErrorDefinition |
|
148
|
|
|
*/ |
|
149
|
2 |
|
public function setData(?stdClass $data): self |
|
150
|
|
|
{ |
|
151
|
2 |
|
$this->data = $data; |
|
152
|
|
|
|
|
153
|
2 |
|
return $this; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @return string|null |
|
158
|
|
|
*/ |
|
159
|
4 |
|
public function getLogLevel(): ?string |
|
160
|
|
|
{ |
|
161
|
4 |
|
return $this->logLevel; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* @param string|null $logLevel |
|
166
|
|
|
* @return RpcErrorDefinition |
|
167
|
|
|
*/ |
|
168
|
|
|
public function setLogLevel(?string $logLevel): self |
|
169
|
|
|
{ |
|
170
|
|
|
$this->logLevel = $logLevel; |
|
171
|
|
|
|
|
172
|
|
|
return $this; |
|
173
|
|
|
} |
|
174
|
|
|
} |
|
175
|
|
|
|