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