1 | <?php |
||
10 | abstract class CheckDefinition |
||
11 | { |
||
12 | /** @var \Spatie\ServerMonitor\Models\Check */ |
||
13 | protected $check; |
||
14 | |||
15 | /** |
||
16 | * @param \Spatie\ServerMonitor\Models\Check $check |
||
17 | * |
||
18 | * @return $this |
||
19 | */ |
||
20 | public function setCheck(Check $check) |
||
21 | { |
||
22 | $this->check = $check; |
||
23 | |||
24 | return $this; |
||
25 | } |
||
26 | |||
27 | public function command(): string |
||
28 | { |
||
29 | return $this->command; |
||
|
|||
30 | } |
||
31 | |||
32 | public function determineResult(Process $process) |
||
33 | { |
||
34 | $this->check->storeProcessOutput($process); |
||
35 | |||
36 | try { |
||
37 | if (! empty($process->getErrorOutput())) { |
||
38 | $this->resolveFailed($process); |
||
39 | |||
40 | return; |
||
41 | } |
||
42 | |||
43 | $this->resolve($process); |
||
44 | } catch (Exception $exception) { |
||
45 | $this->check->fail('Exception occurred: '.$exception->getMessage()); |
||
46 | } |
||
47 | } |
||
48 | |||
49 | abstract public function resolve(Process $process); |
||
50 | |||
51 | public function resolveFailed(Process $process) |
||
52 | { |
||
53 | $this->check->fail("failed to run: {$process->getErrorOutput()}"); |
||
55 | |||
56 | /** |
||
57 | * When a check is emitting a warning or is failing, a notification will only |
||
58 | * be sent once in given amount of minutes. |
||
59 | * |
||
60 | * @return int |
||
61 | */ |
||
62 | public function throttleFailingNotificationsForMinutes(): int |
||
66 | |||
67 | public function performNextRunInMinutes(): int |
||
75 | |||
76 | /** |
||
77 | * The amount of seconds that check may run. |
||
78 | * |
||
79 | * @return int |
||
80 | */ |
||
81 | public function timeoutInSeconds(): int |
||
85 | } |
||
86 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: