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