1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Liip\MonitorBundle\Helper; |
6
|
|
|
|
7
|
|
|
use ArrayObject; |
8
|
|
|
use ZendDiagnostics\Check\CheckInterface; |
9
|
|
|
use ZendDiagnostics\Result\Collection as ResultsCollection; |
10
|
|
|
use ZendDiagnostics\Result\ResultInterface; |
11
|
|
|
use ZendDiagnostics\Runner\Reporter\ReporterInterface; |
12
|
|
|
|
13
|
|
|
abstract class AbstractMailReporter implements ReporterInterface |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var array|string |
17
|
|
|
*/ |
18
|
|
|
protected $recipients; |
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $subject; |
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $sender; |
27
|
|
|
/** |
28
|
|
|
* @var bool |
29
|
|
|
*/ |
30
|
|
|
protected $sendOnWarning; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param string|array $recipients |
34
|
|
|
* @param string $sender |
35
|
|
|
* @param string $subject |
36
|
|
|
* @param bool $sendOnWarning |
37
|
|
|
*/ |
38
|
|
|
public function __construct($recipients, $sender, $subject, $sendOnWarning = true) |
39
|
|
|
{ |
40
|
|
|
$this->recipients = $recipients; |
41
|
|
|
$this->sender = $sender; |
42
|
|
|
$this->subject = $subject; |
43
|
|
|
$this->sendOnWarning = $sendOnWarning; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
|
|
public function onStart(ArrayObject $checks, $runnerConfig) |
50
|
|
|
{ |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
*/ |
56
|
|
|
public function onBeforeRun(CheckInterface $check, $checkAlias = null) |
57
|
|
|
{ |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
|
|
public function onAfterRun(CheckInterface $check, ResultInterface $result, $checkAlias = null) |
64
|
|
|
{ |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
|
|
public function onStop(ResultsCollection $results) |
71
|
|
|
{ |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritdoc} |
76
|
|
|
*/ |
77
|
|
|
public function onFinish(ResultsCollection $results) |
78
|
|
|
{ |
79
|
|
|
if ($results->getUnknownCount() > 0) { |
80
|
|
|
$this->sendEmail($results); |
81
|
|
|
|
82
|
|
|
return; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
if ($results->getWarningCount() > 0 && $this->sendOnWarning) { |
86
|
|
|
$this->sendEmail($results); |
87
|
|
|
|
88
|
|
|
return; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
if ($results->getFailureCount() > 0) { |
92
|
|
|
$this->sendEmail($results); |
93
|
|
|
|
94
|
|
|
return; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
abstract protected function sendEmail(ResultsCollection $results); |
99
|
|
|
} |
100
|
|
|
|