mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 01:36:00 -04:00
c35080d6ce
Within the flow of HttpFetchException, the actual exception from curl is preserved and logged. Make HttpFetchException a pretty exception for when it is shown to users.
39 lines
759 B
PHP
39 lines
759 B
PHP
<?php
|
|
|
|
namespace BookStack\Uploads;
|
|
|
|
use BookStack\Exceptions\HttpFetchException;
|
|
|
|
class HttpFetcher
|
|
{
|
|
/**
|
|
* Fetch content from an external URI.
|
|
*
|
|
* @param string $uri
|
|
*
|
|
* @throws HttpFetchException
|
|
*
|
|
* @return bool|string
|
|
*/
|
|
public function fetch(string $uri)
|
|
{
|
|
$ch = curl_init();
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_URL => $uri,
|
|
CURLOPT_RETURNTRANSFER => 1,
|
|
CURLOPT_CONNECTTIMEOUT => 5,
|
|
]);
|
|
|
|
$data = curl_exec($ch);
|
|
$err = curl_error($ch);
|
|
curl_close($ch);
|
|
|
|
if ($err) {
|
|
$errno = curl_errno($ch);
|
|
throw new HttpFetchException($err, $errno);
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
}
|