|
1
|
|
|
<?php namespace Neomerx\JsonApi\Document; |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright 2015-2018 [email protected] |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
use Neomerx\JsonApi\Contracts\Document\DocumentInterface; |
|
20
|
|
|
use Neomerx\JsonApi\Contracts\Document\ErrorInterface; |
|
21
|
|
|
use Neomerx\JsonApi\Contracts\Document\LinkInterface; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @package Neomerx\JsonApi |
|
25
|
|
|
* |
|
26
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
|
27
|
|
|
*/ |
|
28
|
|
|
class Error implements ErrorInterface |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* @var int|string|null |
|
32
|
|
|
*/ |
|
33
|
|
|
private $idx; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var null|array<string,\Neomerx\JsonApi\Contracts\Schema\LinkInterface> |
|
37
|
|
|
*/ |
|
38
|
|
|
private $links; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var string|null |
|
42
|
|
|
*/ |
|
43
|
|
|
private $status; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var string|null |
|
47
|
|
|
*/ |
|
48
|
|
|
private $code; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var string|null |
|
52
|
|
|
*/ |
|
53
|
|
|
private $title; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @var string|null |
|
57
|
|
|
*/ |
|
58
|
|
|
private $detail; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @var array|null |
|
62
|
|
|
*/ |
|
63
|
|
|
private $source; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @var mixed|null |
|
67
|
|
|
*/ |
|
68
|
|
|
private $meta; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param int|string|null $idx |
|
72
|
|
|
* @param LinkInterface|null $aboutLink |
|
73
|
|
|
* @param string|null $status |
|
74
|
|
|
* @param string|null $code |
|
75
|
|
|
* @param string|null $title |
|
76
|
|
|
* @param string|null $detail |
|
77
|
|
|
* @param array|null $source |
|
78
|
|
|
* @param mixed|null $meta |
|
79
|
|
|
*/ |
|
80
|
33 |
|
public function __construct( |
|
81
|
|
|
$idx = null, |
|
82
|
|
|
LinkInterface $aboutLink = null, |
|
83
|
|
|
string $status = null, |
|
84
|
|
|
string $code = null, |
|
85
|
|
|
string $title = null, |
|
86
|
|
|
string $detail = null, |
|
87
|
|
|
array $source = null, |
|
88
|
|
|
$meta = null |
|
89
|
|
|
) { |
|
90
|
|
|
$this |
|
91
|
33 |
|
->setId($idx) |
|
92
|
33 |
|
->setLink(DocumentInterface::KEYWORD_ERRORS_ABOUT, $aboutLink) |
|
93
|
33 |
|
->setStatus($status) |
|
94
|
33 |
|
->setCode($code) |
|
95
|
33 |
|
->setTitle($title) |
|
96
|
33 |
|
->setDetail($detail) |
|
97
|
33 |
|
->setSource($source) |
|
98
|
33 |
|
->setMeta($meta); |
|
99
|
33 |
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @inheritdoc |
|
103
|
|
|
*/ |
|
104
|
9 |
|
public function getId() |
|
105
|
|
|
{ |
|
106
|
9 |
|
return $this->idx; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @param string|int|null $idx |
|
111
|
|
|
* |
|
112
|
|
|
* @return self |
|
113
|
|
|
*/ |
|
114
|
33 |
|
public function setId($idx): self |
|
115
|
|
|
{ |
|
116
|
33 |
|
assert($idx === null || is_int($idx) === true || is_string($idx) === true); |
|
117
|
|
|
|
|
118
|
33 |
|
$this->idx = $idx; |
|
119
|
|
|
|
|
120
|
33 |
|
return $this; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @inheritdoc |
|
125
|
|
|
*/ |
|
126
|
9 |
|
public function getLinks(): ?array |
|
127
|
|
|
{ |
|
128
|
9 |
|
return $this->links; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @param string $name |
|
133
|
|
|
* @param LinkInterface|null $link |
|
134
|
|
|
* |
|
135
|
|
|
* @return self |
|
136
|
|
|
*/ |
|
137
|
33 |
|
public function setLink(string $name, ?LinkInterface $link): self |
|
138
|
|
|
{ |
|
139
|
33 |
|
if ($link !== null) { |
|
140
|
7 |
|
$this->links[$name] = $link; |
|
141
|
|
|
} else { |
|
142
|
26 |
|
unset($this->links[$name]); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
33 |
|
return $this; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @inheritdoc |
|
150
|
|
|
*/ |
|
151
|
9 |
|
public function getStatus(): ?string |
|
152
|
|
|
{ |
|
153
|
9 |
|
return $this->status; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @param string|null $status |
|
158
|
|
|
* |
|
159
|
|
|
* @return self |
|
160
|
|
|
*/ |
|
161
|
33 |
|
public function setStatus(?string $status): self |
|
162
|
|
|
{ |
|
163
|
33 |
|
$this->status = $status; |
|
164
|
|
|
|
|
165
|
33 |
|
return $this; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* @inheritdoc |
|
170
|
|
|
*/ |
|
171
|
9 |
|
public function getCode(): ?string |
|
172
|
|
|
{ |
|
173
|
9 |
|
return $this->code; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* @param string|null $code |
|
178
|
|
|
* |
|
179
|
|
|
* @return self |
|
180
|
|
|
*/ |
|
181
|
33 |
|
public function setCode(?string $code): self |
|
182
|
|
|
{ |
|
183
|
33 |
|
$this->code = $code; |
|
184
|
|
|
|
|
185
|
33 |
|
return $this; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* @inheritdoc |
|
190
|
|
|
*/ |
|
191
|
10 |
|
public function getTitle(): ?string |
|
192
|
|
|
{ |
|
193
|
10 |
|
return $this->title; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* @param null|string $title |
|
198
|
|
|
* |
|
199
|
|
|
* @return self |
|
200
|
|
|
*/ |
|
201
|
33 |
|
public function setTitle(?string $title): self |
|
202
|
|
|
{ |
|
203
|
33 |
|
$this->title = $title; |
|
204
|
|
|
|
|
205
|
33 |
|
return $this; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* @inheritdoc |
|
210
|
|
|
*/ |
|
211
|
9 |
|
public function getDetail(): ?string |
|
212
|
|
|
{ |
|
213
|
9 |
|
return $this->detail; |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* @param null|string $detail |
|
218
|
|
|
* |
|
219
|
|
|
* @return self |
|
220
|
|
|
*/ |
|
221
|
33 |
|
public function setDetail(?string $detail): self |
|
222
|
|
|
{ |
|
223
|
33 |
|
$this->detail = $detail; |
|
224
|
|
|
|
|
225
|
33 |
|
return $this; |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* @inheritdoc |
|
230
|
|
|
*/ |
|
231
|
19 |
|
public function getSource(): ?array |
|
232
|
|
|
{ |
|
233
|
19 |
|
return $this->source; |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
/** |
|
237
|
|
|
* @param array|null $source |
|
238
|
|
|
* |
|
239
|
|
|
* @return self |
|
240
|
|
|
*/ |
|
241
|
33 |
|
public function setSource(?array $source): self |
|
242
|
|
|
{ |
|
243
|
33 |
|
$this->source = $source; |
|
244
|
|
|
|
|
245
|
33 |
|
return $this; |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
/** |
|
249
|
|
|
* @inheritdoc |
|
250
|
|
|
*/ |
|
251
|
9 |
|
public function getMeta() |
|
252
|
|
|
{ |
|
253
|
9 |
|
return $this->meta; |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
/** |
|
257
|
|
|
* @param mixed|null $meta |
|
258
|
|
|
* |
|
259
|
|
|
* @return self |
|
260
|
|
|
*/ |
|
261
|
33 |
|
public function setMeta($meta): self |
|
262
|
|
|
{ |
|
263
|
33 |
|
$this->meta = $meta; |
|
264
|
|
|
|
|
265
|
33 |
|
return $this; |
|
266
|
|
|
} |
|
267
|
|
|
} |
|
268
|
|
|
|