1 | <?php |
||
10 | class HealthBuilder |
||
11 | { |
||
12 | /** |
||
13 | * @var Status |
||
14 | */ |
||
15 | public $status; |
||
16 | |||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | public $details; |
||
21 | |||
22 | /** |
||
23 | * Create new Builder instance. |
||
24 | * |
||
25 | * @param Status $status |
||
26 | * @param array $details |
||
27 | */ |
||
28 | 108 | public function __construct(Status $status = null, $details = array()) |
|
37 | |||
38 | /** |
||
39 | * Set status to Status::DOWN and add details for given Exception if available. |
||
40 | * |
||
41 | * @param \Exception $exception The exception |
||
42 | * @return HealthBuilder |
||
43 | */ |
||
44 | 30 | public function down(\Exception $exception = null) |
|
45 | { |
||
46 | 30 | $builder = $this->status(new Status(Status::DOWN)); |
|
47 | |||
48 | 30 | if (!is_null($exception)) { |
|
49 | 15 | $builder->withException($exception); |
|
50 | 15 | } |
|
51 | |||
52 | 30 | return $builder; |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * Create a new Builder instance with a Status::UNKNOWN status. |
||
57 | * |
||
58 | * @return HealthBuilder |
||
59 | */ |
||
60 | 21 | public function unknown() |
|
64 | |||
65 | /** |
||
66 | * Create a new Builder instance with a Status::UP status. |
||
67 | * |
||
68 | * @return HealthBuilder |
||
69 | */ |
||
70 | 18 | public function up() |
|
74 | |||
75 | /** |
||
76 | * Create a new Builder instance with a Status::OUT_OF_SERVICE status. |
||
77 | * |
||
78 | * @return HealthBuilder |
||
79 | */ |
||
80 | 3 | public function outOfService() |
|
84 | |||
85 | /** |
||
86 | * Set status to given Status instance or status code. |
||
87 | * |
||
88 | * @param Status|string $status |
||
89 | * @return $this |
||
90 | */ |
||
91 | 90 | public function status($status) |
|
100 | |||
101 | /** |
||
102 | * Record detail for given {@link Exception}. |
||
103 | * |
||
104 | * @param \Exception $exception |
||
105 | * @return $this |
||
106 | */ |
||
107 | 18 | public function withException(\Exception $exception) |
|
112 | |||
113 | /** |
||
114 | * Record detail using key and message. |
||
115 | * |
||
116 | * @param string $key the detail key |
||
117 | * @param string $message the detail message |
||
118 | * @return $this |
||
119 | */ |
||
120 | 57 | public function withDetail($key, $message) |
|
127 | |||
128 | /** |
||
129 | * @return Health |
||
130 | */ |
||
131 | 105 | public function build() |
|
135 | } |
||
136 |