1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author: Viskov Sergey |
4
|
|
|
* @date : 4/12/16 |
5
|
|
|
* @time : 1:00 PM |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace LTDBeget\dns\configurator\errors; |
9
|
|
|
|
10
|
|
|
use LTDBeget\dns\configurator\Zone; |
11
|
|
|
use LTDBeget\dns\configurator\zoneEntities\Node; |
12
|
|
|
use LTDBeget\dns\configurator\zoneEntities\record\base\Record; |
13
|
|
|
use LTDBeget\dns\enums\eErrorCode; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class ValidationError |
17
|
|
|
* |
18
|
|
|
* @package LTDBeget\dns\configurator\errors |
19
|
|
|
*/ |
20
|
|
|
class ValidationError |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var Zone |
24
|
|
|
*/ |
25
|
|
|
private $zone; |
26
|
|
|
/** |
27
|
|
|
* @var Node |
28
|
|
|
*/ |
29
|
|
|
private $node; |
30
|
|
|
/** |
31
|
|
|
* @var Record |
32
|
|
|
*/ |
33
|
|
|
private $record; |
34
|
|
|
/** |
35
|
|
|
* @var eErrorCode |
36
|
|
|
*/ |
37
|
|
|
private $errorCode; |
38
|
|
|
/** |
39
|
|
|
* @var String |
40
|
|
|
*/ |
41
|
|
|
private $checkedAttribute; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* closed. Make instance only via static methods |
45
|
|
|
*/ |
46
|
1 |
|
private function __construct() |
47
|
|
|
{ |
48
|
1 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param Zone $zone |
52
|
|
|
* @param eErrorCode $errorCode |
53
|
|
|
* @return ValidationError |
54
|
|
|
*/ |
55
|
|
|
public static function makeZoneError(Zone $zone, eErrorCode $errorCode) : ValidationError |
56
|
|
|
{ |
57
|
|
|
$error = new self; |
58
|
|
|
$error->zone = $zone; |
59
|
|
|
$error->errorCode = $errorCode; |
60
|
|
|
|
61
|
|
|
return $error; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param Node $node |
66
|
|
|
* @param eErrorCode $errorCode |
67
|
|
|
* @return ValidationError |
68
|
|
|
*/ |
69
|
|
|
public static function makeNodeError(Node $node, eErrorCode $errorCode) : ValidationError |
70
|
|
|
{ |
71
|
|
|
$error = new self; |
72
|
|
|
$error->zone = $node->getZone(); |
73
|
|
|
$error->node = $node; |
74
|
|
|
$error->errorCode = $errorCode; |
75
|
|
|
|
76
|
|
|
return $error; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param Record $record |
81
|
|
|
* @param eErrorCode $errorCode |
82
|
|
|
* @param $checked_atribute |
83
|
|
|
* @return ValidationError |
84
|
|
|
*/ |
85
|
1 |
|
public static function makeRecordError(Record $record, eErrorCode $errorCode, $checked_atribute) : ValidationError |
86
|
|
|
{ |
87
|
1 |
|
$error = new self; |
88
|
1 |
|
$error->zone = $record->getNode()->getZone(); |
89
|
1 |
|
$error->node = $record->getNode(); |
90
|
1 |
|
$error->record = $record; |
91
|
1 |
|
$error->errorCode = $errorCode; |
92
|
1 |
|
$error->checkedAttribute = $checked_atribute; |
93
|
|
|
|
94
|
1 |
|
return $error; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return array |
99
|
|
|
*/ |
100
|
|
|
public function toArray() : array |
101
|
|
|
{ |
102
|
|
|
$errorArray = []; |
103
|
|
|
$errorArray['code'] = $this->errorCode->getValue(); |
104
|
|
|
$errorArray['errorText'] = $this->errorCode->getText(); |
105
|
|
|
$errorArray['origin'] = $this->zone->getOrigin(); |
106
|
|
|
|
107
|
|
|
if (NULL !== $this->node) { |
108
|
|
|
$errorArray['node'] = $this->node->getName(); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
if (NULL !== $this->record) { |
112
|
|
|
$errorArray['recordData'] = $this->record->toArray(); |
113
|
|
|
$errorArray['checkedAttribute'] = $this->checkedAttribute; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
return $errorArray; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return Zone |
121
|
|
|
*/ |
122
|
|
|
public function getZone() |
123
|
|
|
{ |
124
|
|
|
return $this->zone; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @return Node |
129
|
|
|
*/ |
130
|
|
|
public function getNode() : Node |
131
|
|
|
{ |
132
|
|
|
if(! $this->isHasNode()) { |
133
|
|
|
throw new \RuntimeException('ValidationError has no Node'); |
134
|
|
|
} |
135
|
|
|
return $this->node; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @return bool |
140
|
|
|
*/ |
141
|
|
|
public function isHasNode() : bool |
142
|
|
|
{ |
143
|
|
|
return NULL !== $this->node; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @return Record |
148
|
|
|
*/ |
149
|
|
|
public function getRecord() : Record |
150
|
|
|
{ |
151
|
|
|
if(! $this->isHasRecord()) { |
152
|
|
|
throw new \RuntimeException('ValidationError has no Record'); |
153
|
|
|
} |
154
|
|
|
return $this->record; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @return bool |
159
|
|
|
*/ |
160
|
|
|
public function isHasRecord() : bool |
161
|
|
|
{ |
162
|
|
|
return NULL !== $this->record; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @return eErrorCode |
167
|
|
|
*/ |
168
|
|
|
public function getErrorCode(): eErrorCode |
169
|
|
|
{ |
170
|
|
|
return $this->errorCode; |
171
|
|
|
} |
172
|
|
|
} |