1 | <?php |
||
8 | class Service |
||
9 | { |
||
10 | /** |
||
11 | * @var ResourceChecker |
||
12 | */ |
||
13 | private $resourceChecker; |
||
14 | |||
15 | /** |
||
16 | * @var Cache |
||
17 | */ |
||
18 | private $cache; |
||
19 | |||
20 | /** |
||
21 | * Service constructor. |
||
22 | * |
||
23 | * @param ResourceChecker $resourceChecker |
||
24 | * @param Cache $cache |
||
25 | */ |
||
26 | public function __construct(ResourceChecker $resourceChecker, Cache $cache) |
||
27 | { |
||
28 | $this->resourceChecker = $resourceChecker; |
||
29 | |||
30 | $this->cache = $cache; |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * Check Resources. |
||
35 | * |
||
36 | * @param bool $force |
||
37 | * @return \Illuminate\Support\Collection |
||
38 | * @throws \Exception |
||
39 | */ |
||
40 | public function checkResources($force = false) |
||
44 | |||
45 | /** |
||
46 | * Check one resource. |
||
47 | * |
||
48 | * @param $slug |
||
49 | * @return array |
||
50 | * @throws \Exception |
||
51 | */ |
||
52 | public function checkResource($slug) |
||
56 | |||
57 | /** |
||
58 | * Get services health. |
||
59 | * |
||
60 | * @return mixed |
||
61 | * @throws \Exception |
||
62 | */ |
||
63 | public function health() |
||
67 | |||
68 | /** |
||
69 | * Get resources. |
||
70 | * |
||
71 | * @return mixed |
||
72 | * @throws \Exception |
||
73 | */ |
||
74 | public function getResources() |
||
78 | |||
79 | /** |
||
80 | * Get a silent checker and notifier closure. |
||
81 | * |
||
82 | * @return \Closure |
||
83 | */ |
||
84 | public function getSilentChecker() |
||
85 | { |
||
86 | return function () { |
||
87 | return $this->checkResources(); |
||
88 | }; |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * Make a string result of all resources. |
||
93 | * |
||
94 | * @param $string |
||
95 | * @param $checkSystem |
||
96 | * @return string |
||
97 | */ |
||
98 | private function makeString($string, $checkSystem) |
||
99 | { |
||
100 | return |
||
101 | $string. |
||
102 | ($checkSystem |
||
103 | ? config('health.string.ok') |
||
104 | : config('health.string.fail')); |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * Check and get a resource. |
||
109 | * |
||
110 | * @param $name |
||
111 | * @return mixed |
||
112 | * @throws \Exception |
||
113 | */ |
||
114 | public function resource($slug) |
||
118 | |||
119 | /** |
||
120 | * Set the action. |
||
121 | * |
||
122 | * @param $action |
||
123 | */ |
||
124 | public function setAction($action) |
||
125 | { |
||
126 | $this->resourceChecker->setCurrentAction($action); |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * @return mixed |
||
131 | * @throws \Exception |
||
132 | */ |
||
133 | public function string() |
||
145 | } |
||
146 |