/**
* @return bool
*/
public function download()
{
if ($this->isDownloaded()) {
return true;
}
$httpClient = new Client();
$request = new Request('GET', $this->getUrl());
$response = $httpClient->send($request, [RequestOptions::PROGRESS => function ($total, $current) {
if ($total <= 0 || !$this->output) {
return;
}
if (!$this->progressBar) {
$this->progressBar = new ProgressBar($this->output, $total);
$this->progressBar->setPlaceholderFormatterDefinition('max', function (ProgressBar $bar) {
return $this->formatSize($bar->getMaxSteps());
});
$this->progressBar->setPlaceholderFormatterDefinition('current', function (ProgressBar $bar) {
return str_pad($this->formatSize($bar->getProgress()), 11, ' ', STR_PAD_LEFT);
});
}
$this->progressBar->setProgress($current);
}]);
$this->filesystem->dumpFile($this->getDestinationFile(), $response->getBody()->getContents());
$this->downloaded = true;
return true;
}