Changeset View
Changeset View
Standalone View
Standalone View
src/future/http/HTTPSFuture.php
Show First 20 Lines • Show All 126 Lines • ▼ Show 20 Lines | final class HTTPSFuture extends BaseHTTPFuture { | ||||
* Load contents of remote URI. Behaves pretty much like | * Load contents of remote URI. Behaves pretty much like | ||||
* `@file_get_contents($uri)` but doesn't require `allow_url_fopen`. | * `@file_get_contents($uri)` but doesn't require `allow_url_fopen`. | ||||
* | * | ||||
* @param string | * @param string | ||||
* @param float | * @param float | ||||
* @return string|false | * @return string|false | ||||
*/ | */ | ||||
public static function loadContent($uri, $timeout = null) { | public static function loadContent($uri, $timeout = null) { | ||||
$future = new HTTPSFuture($uri); | $future = new self($uri); | ||||
if ($timeout !== null) { | if ($timeout !== null) { | ||||
$future->setTimeout($timeout); | $future->setTimeout($timeout); | ||||
} | } | ||||
try { | try { | ||||
list($body) = $future->resolvex(); | list($body) = $future->resolvex(); | ||||
return $body; | return $body; | ||||
} catch (HTTPFutureResponseStatus $ex) { | } catch (HTTPFutureResponseStatus $ex) { | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
public function setDownloadPath($download_path) { | public function setDownloadPath($download_path) { | ||||
$this->downloadPath = $download_path; | $this->downloadPath = $download_path; | ||||
if (Filesystem::pathExists($download_path)) { | if (Filesystem::pathExists($download_path)) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Specified download path "%s" already exists, refusing to '. | 'Specified download path "%s" already exists, refusing to '. | ||||
'overwrite.')); | 'overwrite.', | ||||
$download_path)); | |||||
} | } | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setProgressSink(PhutilProgressSink $progress_sink) { | public function setProgressSink(PhutilProgressSink $progress_sink) { | ||||
$this->progressSink = $progress_sink; | $this->progressSink = $progress_sink; | ||||
return $this; | return $this; | ||||
▲ Show 20 Lines • Show All 715 Lines • Show Last 20 Lines |