1
|
|
|
<?php |
2
|
|
|
namespace Yoanm\JsonRpcServerDoc\Domain\Model; |
3
|
|
|
|
4
|
|
|
use Yoanm\JsonRpcServerDoc\Domain\Model\Type\TypeDoc; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class ErrorDoc |
8
|
|
|
*/ |
9
|
|
|
class ErrorDoc |
10
|
|
|
{ |
11
|
|
|
/** @var string */ |
12
|
|
|
private $title; |
13
|
|
|
/** @var int */ |
14
|
|
|
private $code; |
15
|
|
|
/** @var string|null */ |
16
|
|
|
private $message = null; |
17
|
|
|
/** @var TypeDoc|null */ |
18
|
|
|
private $dataDoc = null; |
19
|
|
|
/** @var string */ |
20
|
|
|
private $identifier; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param string $title |
24
|
|
|
* @param int $code |
25
|
|
|
* @param string|null $message |
26
|
|
|
* @param TypeDoc|null $dataDoc |
27
|
|
|
* @param string|null $identifier |
28
|
|
|
*/ |
29
|
13 |
|
public function __construct( |
30
|
|
|
string $title, |
31
|
|
|
int $code, |
32
|
|
|
string $message = null, |
33
|
|
|
TypeDoc $dataDoc = null, |
34
|
|
|
string $identifier = null |
35
|
|
|
) { |
36
|
13 |
|
$this->title = $title; |
37
|
13 |
|
$this->code = $code; |
38
|
13 |
|
$this->message = $message; |
39
|
13 |
|
$this->dataDoc = $dataDoc; |
40
|
|
|
// Use title and code as id if not provided |
41
|
13 |
|
$this->setIdentifier($identifier ?? $title.((string)$code)); |
42
|
13 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param string $message |
46
|
|
|
*/ |
47
|
1 |
|
public function setMessage(string $message): ErrorDoc |
48
|
|
|
{ |
49
|
1 |
|
$this->message = $message; |
50
|
|
|
|
51
|
1 |
|
return $this; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param string $identifier |
56
|
|
|
* |
57
|
|
|
* @return ErrorDoc |
58
|
|
|
*/ |
59
|
13 |
|
public function setIdentifier(string $identifier) : ErrorDoc |
60
|
|
|
{ |
61
|
|
|
// Sanitize Identifier => remove space and slashes |
62
|
13 |
|
$this->identifier = strtr( |
63
|
13 |
|
ucwords(strtr( |
64
|
13 |
|
$identifier, |
65
|
13 |
|
['_' => ' ', '/' => '-', '.' => '_ ', '\\' => '_ '] |
66
|
|
|
)), |
67
|
13 |
|
[' ' => ''] |
68
|
|
|
); |
69
|
|
|
|
70
|
13 |
|
return $this; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param TypeDoc $dataDoc |
75
|
|
|
* |
76
|
|
|
* @return ErrorDoc |
77
|
|
|
*/ |
78
|
1 |
|
public function setDataDoc(TypeDoc $dataDoc) : ErrorDoc |
79
|
|
|
{ |
80
|
1 |
|
$this->dataDoc = $dataDoc; |
81
|
|
|
|
82
|
1 |
|
return $this; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return string |
87
|
|
|
*/ |
88
|
1 |
|
public function getTitle() : string |
89
|
|
|
{ |
90
|
1 |
|
return $this->title; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return int |
95
|
|
|
*/ |
96
|
1 |
|
public function getCode() : int |
97
|
|
|
{ |
98
|
1 |
|
return $this->code; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return string|null |
103
|
|
|
*/ |
104
|
3 |
|
public function getMessage() : ?string |
105
|
|
|
{ |
106
|
3 |
|
return $this->message; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return TypeDoc|null |
111
|
|
|
*/ |
112
|
3 |
|
public function getDataDoc() : ?TypeDoc |
113
|
|
|
{ |
114
|
3 |
|
return $this->dataDoc; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return string |
119
|
|
|
*/ |
120
|
7 |
|
public function getIdentifier() : string |
121
|
|
|
{ |
122
|
7 |
|
return $this->identifier; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|