public function download()
{
if (!ini_get('allow_url_fopen')) {
throw new Exception('allow_url_fopen is disabled.');
}
// open the temp file for writing
$fileHandle = fopen($this->path, 'wb');
if ($fileHandle === false) {
throw new Exception('Could not open temp file.');
}
$caPath = CaBundle::getSystemCaRootBundlePath();
if (is_dir($caPath)) {
$streamOptions = array('ssl' => array('capath' => $caPath));
} else {
$streamOptions = array('ssl' => array('cafile' => $caPath));
}
$streamParams = array('notification' => array($this, 'showDownloadProgress'));
// download context so we can track download progress
$downloadContext = stream_context_create($streamOptions, $streamParams);
// open the download url for reading
$downloadHandle = @fopen($this->url, 'rb', false, $downloadContext);
if ($downloadHandle === false) {
throw new Exception('Could not download installation file.');
}
while (!feof($downloadHandle)) {
if (fwrite($fileHandle, fread($downloadHandle, 1024)) === false) {
throw new Exception('Could not write installation file to disk.');
}
}
fclose($downloadHandle);
fclose($fileHandle);
if ($this->progressBar) {
$this->progressBar->finish();
$this->output->writeln('');
}
return $this->path;
}