Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 31 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
FileService | |
0.00% |
0 / 31 |
|
0.00% |
0 / 2 |
90 | |
0.00% |
0 / 1 |
getStatus | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
42 | |||
getUri | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | /** @noinspection PhpUnhandledExceptionInspection */ |
3 | declare(strict_types=1); |
4 | // TODO unit-test |
5 | // TODO find a way to integrate this in e2e-tests |
6 | |
7 | class FileService { |
8 | static function getStatus(): string { |
9 | if (!SystemConfig::$fileService_external or !SystemConfig::$fileService_internal) { |
10 | return 'off'; |
11 | } |
12 | |
13 | $uri = 'http://' . SystemConfig::$fileService_internal . '/health'; |
14 | |
15 | $curl = curl_init(); |
16 | curl_setopt_array($curl, [ |
17 | CURLOPT_URL => $uri, |
18 | CURLOPT_RETURNTRANSFER => true, |
19 | CURLOPT_ENCODING => "", |
20 | CURLOPT_MAXREDIRS => 10, |
21 | CURLOPT_TIMEOUT => 5, |
22 | CURLOPT_FOLLOWLOCATION => true, |
23 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
24 | CURLOPT_CUSTOMREQUEST => 'GET', |
25 | CURLOPT_FAILONERROR => false, // allows to read body on error |
26 | CURLOPT_HTTPHEADER => [ |
27 | "Content-Type: text/plain" |
28 | ], |
29 | ]); |
30 | |
31 | $curlResponse = curl_exec($curl); |
32 | $errorCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); |
33 | |
34 | if (($errorCode === 0) or ($curlResponse === false)) { |
35 | |
36 | error_log("FilesService responds Error on `[GET] $uri`: not available"); |
37 | return 'unreachable'; |
38 | } |
39 | |
40 | if ($errorCode >= 400) { |
41 | error_log("BroadcastingService responds Error on `[GET] $uri`: [$errorCode] $curlResponse"); |
42 | return 'unreachable'; |
43 | } |
44 | |
45 | return 'on'; |
46 | } |
47 | |
48 | public static function getUri(): string { |
49 | if (!SystemConfig::$fileService_external) { |
50 | return Server::getUrl() . '/'; |
51 | } |
52 | $proto = (SystemConfig::$system_tlsEnabled ? 'https://' : 'http://'); |
53 | return $proto . SystemConfig::$fileService_external; |
54 | } |
55 | } |