Platformsh\Cli\SelfUpdate\ManifestStrategy::download PHP Method

download() public method

public download ( Humbug\SelfUpdate\Updater $updater )
$updater Humbug\SelfUpdate\Updater
    public function download(Updater $updater)
    {
        $versionInfo = $this->getRemoteVersionInfo($updater);
        $context = stream_context_create(['http' => ['timeout' => $this->downloadTimeout]]);
        $fileContents = file_get_contents($versionInfo['url'], false, $context);
        if ($fileContents === false) {
            throw new HttpRequestException(sprintf('Failed to download file from URL: %s', $versionInfo['url']));
        }
        $tmpFilename = $updater->getTempPharFile();
        if (file_put_contents($tmpFilename, $fileContents) === false) {
            throw new \RuntimeException(sprintf('Failed to write file: %s', $tmpFilename));
        }
        $tmpSha = sha1_file($tmpFilename);
        if ($tmpSha !== $versionInfo['sha1']) {
            unlink($tmpFilename);
            throw new \RuntimeException(sprintf('SHA-1 verification failed: expected %s, actual %s', $versionInfo['sha1'], $tmpSha));
        }
    }