Conditions | 6 |
Paths | 6 |
Total Lines | 31 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
21 | public static function WEBSERVICE(string $url) |
||
22 | { |
||
23 | $url = trim($url); |
||
24 | if (strlen($url) > 2048) { |
||
25 | return Functions::VALUE(); // Invalid URL length |
||
26 | } |
||
27 | |||
28 | if (!preg_match('/^http[s]?:\/\//', $url)) { |
||
29 | return Functions::VALUE(); // Invalid protocol |
||
30 | } |
||
31 | |||
32 | // Get results from the the webservice |
||
33 | $client = Settings::getHttpClient(); |
||
34 | $request = new Request('GET', $url); |
||
35 | |||
36 | try { |
||
37 | $response = $client->sendRequest($request); |
||
38 | } catch (ClientExceptionInterface $e) { |
||
39 | return Functions::VALUE(); // cURL error |
||
40 | } |
||
41 | |||
42 | if ($response->getStatusCode() != 200) { |
||
43 | return Functions::VALUE(); // cURL error |
||
44 | } |
||
45 | |||
46 | $output = (string) $response->getBody(); |
||
47 | if (strlen($output) > 32767) { |
||
48 | return Functions::VALUE(); // Output not a string or too long |
||
49 | } |
||
50 | |||
51 | return $output; |
||
52 | } |
||
54 |