protected function download($params)
{
$options = array_merge(['repo' => 'getkirby/starterkit', 'branch' => 'master', 'zip' => null, 'output' => null], $params);
extract($options);
if (!$zip) {
throw new RuntimeException('Please provide a zip file');
}
// build the download url
$url = 'https://github.com/' . $repo . '/archive/' . $branch . '.zip';
// generate some usable output
if ($output) {
$output->writeln('<info>Downloading from: ' . $url . '</info>');
}
// send the remote request
$download = util::download($url, function ($resource, $total, $downloaded) use($output) {
if (!$output) {
return null;
}
if ($downloaded && $total) {
$output->write('Downloaded: ' . round($downloaded / $total, 2) * 100 . "%\r");
}
});
// write the result to the disk
file_put_contents($zip, $download);
}