]> BookStack Code Mirror - bookstack/blob - app/Uploads/HttpFetcher.php
Added more complexity in an attempt to make ldap host failover fit
[bookstack] / app / Uploads / HttpFetcher.php
1 <?php
2
3 namespace BookStack\Uploads;
4
5 use BookStack\Exceptions\HttpFetchException;
6
7 class HttpFetcher
8 {
9     /**
10      * Fetch content from an external URI.
11      *
12      * @param string $uri
13      *
14      * @throws HttpFetchException
15      *
16      * @return bool|string
17      */
18     public function fetch(string $uri)
19     {
20         $ch = curl_init();
21         curl_setopt_array($ch, [
22             CURLOPT_URL            => $uri,
23             CURLOPT_RETURNTRANSFER => 1,
24             CURLOPT_CONNECTTIMEOUT => 5,
25         ]);
26
27         $data = curl_exec($ch);
28         $err = curl_error($ch);
29         curl_close($ch);
30
31         if ($err) {
32             throw new HttpFetchException($err);
33         }
34
35         return $data;
36     }
37 }