1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TonicHealthCheck\Check; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class AbstractCheck. |
9
|
|
|
*/ |
10
|
|
|
abstract class AbstractCheck implements CheckInterface |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var null|string |
14
|
|
|
*/ |
15
|
|
|
protected $checkNode = self::CHECK_NODE_DEFAULT; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var ResultInterface |
19
|
|
|
*/ |
20
|
|
|
protected $lastCheckResult = null; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* AbstractCheck constructor. |
24
|
|
|
* |
25
|
|
|
* @param null $checkNode |
26
|
|
|
*/ |
27
|
7 |
|
public function __construct($checkNode = null) |
28
|
|
|
{ |
29
|
7 |
|
if (null !== $checkNode) { |
30
|
7 |
|
$this->setCheckNode($checkNode); |
31
|
7 |
|
} |
32
|
7 |
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return string |
36
|
|
|
*/ |
37
|
2 |
|
public function getCheckComponent() |
38
|
|
|
{ |
39
|
2 |
|
return static::COMPONENT; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return string |
44
|
|
|
*/ |
45
|
2 |
|
public function getCheckGroup() |
46
|
|
|
{ |
47
|
2 |
|
return static::GROUP; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return null|string |
52
|
|
|
*/ |
53
|
2 |
|
public function getCheckNode() |
54
|
|
|
{ |
55
|
2 |
|
return $this->checkNode; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
2 |
|
public function getCheckIdent() |
62
|
|
|
{ |
63
|
2 |
|
return static::CHECK; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return null|string |
68
|
|
|
*/ |
69
|
2 |
|
public function getIndent() |
70
|
|
|
{ |
71
|
2 |
|
return $this->getCheckNode().'.'.$this->getCheckGroup().'.'.$this->getCheckComponent().'.'.$this->getCheckIdent(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return null|string |
76
|
|
|
*/ |
77
|
1 |
|
public function getLabel() |
78
|
|
|
{ |
79
|
1 |
|
return $this->getIndent(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return ResultInterface |
84
|
|
|
*/ |
85
|
1 |
|
public function getLastCheckResult() |
86
|
|
|
{ |
87
|
1 |
|
return $this->lastCheckResult; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return ResultInterface |
92
|
|
|
*/ |
93
|
4 |
|
public function check() |
94
|
|
|
{ |
95
|
|
|
try { |
96
|
4 |
|
$this->performCheck(); |
97
|
1 |
|
$checkResult = new Success(); |
98
|
4 |
|
} catch (CheckException $exception) { |
99
|
2 |
|
$checkResult = new Failure($exception->getCode(), $exception); |
100
|
3 |
|
} catch (Exception $exception) { |
101
|
1 |
|
$errorUnexpected = CheckUnexpectedException::catchUnexpectedError(__CLASS__, __METHOD__, $exception); |
102
|
1 |
|
$checkResult = new Failure($errorUnexpected->getCode(), $errorUnexpected); |
103
|
|
|
} |
104
|
|
|
|
105
|
4 |
|
$this->setLastCheckResult($checkResult); |
106
|
|
|
|
107
|
4 |
|
return $checkResult; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param string $checkNode |
112
|
|
|
*/ |
113
|
7 |
|
protected function setCheckNode($checkNode) |
114
|
|
|
{ |
115
|
7 |
|
$this->checkNode = $checkNode; |
116
|
7 |
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param ResultInterface $lastCheckResult |
120
|
|
|
*/ |
121
|
4 |
|
protected function setLastCheckResult(ResultInterface $lastCheckResult) |
122
|
|
|
{ |
123
|
4 |
|
$this->lastCheckResult = $lastCheckResult; |
124
|
4 |
|
} |
125
|
|
|
} |
126
|
|
|
|