1
0
Fork 0

Add docblocks to HttpDownloader, refs #9209

pull/9519/head
Jordi Boggiano 2020-11-25 15:44:59 +01:00
parent e8a3a33023
commit 08f0af4623
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 58 additions and 1 deletions

View File

@ -73,6 +73,16 @@ class HttpDownloader
$this->rfs = new RemoteFilesystem($io, $config, $options, $disableTls); $this->rfs = new RemoteFilesystem($io, $config, $options, $disableTls);
} }
/**
* Download a file synchronously
*
* @param string $url URL to download
* @param array $options Stream context options e.g. https://www.php.net/manual/en/context.http.php
* although not all options are supported when using the default curl downloader
* @return Response
*
* @throws TransportException
*/
public function get($url, $options = array()) public function get($url, $options = array())
{ {
list($job) = $this->addJob(array('url' => $url, 'options' => $options, 'copyTo' => false), true); list($job) = $this->addJob(array('url' => $url, 'options' => $options, 'copyTo' => false), true);
@ -101,6 +111,16 @@ class HttpDownloader
return $response; return $response;
} }
/**
* Create an async download operation
*
* @param string $url URL to download
* @param array $options Stream context options e.g. https://www.php.net/manual/en/context.http.php
* although not all options are supported when using the default curl downloader
* @return Promise
*
* @throws TransportException
*/
public function add($url, $options = array()) public function add($url, $options = array())
{ {
list(, $promise) = $this->addJob(array('url' => $url, 'options' => $options, 'copyTo' => false)); list(, $promise) = $this->addJob(array('url' => $url, 'options' => $options, 'copyTo' => false));
@ -108,6 +128,17 @@ class HttpDownloader
return $promise; return $promise;
} }
/**
* Copy a file synchronously
*
* @param string $url URL to download
* @param string $to Path to copy to
* @param array $options Stream context options e.g. https://www.php.net/manual/en/context.http.php
* although not all options are supported when using the default curl downloader
* @return Response
*
* @throws TransportException
*/
public function copy($url, $to, $options = array()) public function copy($url, $to, $options = array())
{ {
list($job) = $this->addJob(array('url' => $url, 'options' => $options, 'copyTo' => $to), true); list($job) = $this->addJob(array('url' => $url, 'options' => $options, 'copyTo' => $to), true);
@ -116,6 +147,17 @@ class HttpDownloader
return $this->getResponse($job['id']); return $this->getResponse($job['id']);
} }
/**
* Create an async copy operation
*
* @param string $url URL to download
* @param string $to Path to copy to
* @param array $options Stream context options e.g. https://www.php.net/manual/en/context.http.php
* although not all options are supported when using the default curl downloader
* @return Promise
*
* @throws TransportException
*/
public function addCopy($url, $to, $options = array()) public function addCopy($url, $to, $options = array())
{ {
list(, $promise) = $this->addJob(array('url' => $url, 'options' => $options, 'copyTo' => $to)); list(, $promise) = $this->addJob(array('url' => $url, 'options' => $options, 'copyTo' => $to));
@ -287,6 +329,11 @@ class HttpDownloader
$this->runningJobs--; $this->runningJobs--;
} }
/**
* Wait for current async download jobs to complete
*
* @param int|null $index For internal use only, the job id
*/
public function wait($index = null) public function wait($index = null)
{ {
while (true) { while (true) {
@ -309,6 +356,7 @@ class HttpDownloader
/** /**
* @internal * @internal
* *
* @param int|null $index For internal use only, the job id
* @return int number of active (queued or started) jobs * @return int number of active (queued or started) jobs
*/ */
public function countActiveJobs($index = null) public function countActiveJobs($index = null)
@ -362,6 +410,9 @@ class HttpDownloader
return $resp; return $resp;
} }
/**
* @internal
*/
public static function outputWarnings(IOInterface $io, $url, $data) public static function outputWarnings(IOInterface $io, $url, $data)
{ {
foreach (array('warning', 'info') as $type) { foreach (array('warning', 'info') as $type) {
@ -382,6 +433,9 @@ class HttpDownloader
} }
} }
/**
* @internal
*/
public static function getExceptionHints(\Exception $e) public static function getExceptionHints(\Exception $e)
{ {
if (!$e instanceof TransportException) { if (!$e instanceof TransportException) {
@ -427,6 +481,9 @@ class HttpDownloader
return true; return true;
} }
/**
* @internal
*/
public static function isCurlEnabled() public static function isCurlEnabled()
{ {
return \extension_loaded('curl') && \function_exists('curl_multi_exec') && \function_exists('curl_multi_init'); return \extension_loaded('curl') && \function_exists('curl_multi_exec') && \function_exists('curl_multi_init');