PhpBrew\Tasks\DownloadTask::download PHP Method

download() public method

public download ( $url, $dir, $md5 = null )
    public function download($url, $dir, $md5 = null)
    {
        if (!is_writable($dir)) {
            throw new Exception("Directory is not writable: {$dir}");
        }
        $downloader = DownloadFactory::getInstance($this->logger, $this->options);
        $basename = $downloader->resolveDownloadFileName($url);
        if (!$basename) {
            throw new Exception("Can not parse url: {$url}");
        }
        $targetFilePath = $dir . DIRECTORY_SEPARATOR . $basename;
        if (!$this->options->force && file_exists($targetFilePath)) {
            $this->logger->info('Checking distribution checksum...');
            $md5a = md5_file($targetFilePath);
            if ($md5 && $md5a != $md5) {
                $this->logger->warn("Checksum mismatch: {$md5a} != {$md5}");
                $this->logger->info('Re-Downloading...');
                $downloader->download($url, $targetFilePath);
            } else {
                $this->logger->info('Checksum matched: ' . $md5);
            }
        } else {
            $downloader->download($url, $targetFilePath);
        }
        return $targetFilePath;
    }

Usage Example

Example #1
0
 public function execute($version)
 {
     $version = preg_replace('/^php-/', '', $version);
     $releaseList = ReleaseList::getReadyInstance($this->options);
     $releases = $releaseList->getReleases();
     $versionInfo = $releaseList->getVersion($version);
     if (!$versionInfo) {
         throw new Exception("Version {$version} not found.");
     }
     $version = $versionInfo['version'];
     $distUrl = 'http://www.php.net/get/' . $versionInfo['filename'] . '/from/this/mirror';
     if ($mirrorSite = $this->options->mirror) {
         // http://tw1.php.net/distributions/php-5.3.29.tar.bz2
         $distUrl = $mirrorSite . '/distributions/' . $versionInfo['filename'];
     }
     $prepare = new PrepareDirectoryTask($this->logger, $this->options);
     $prepare->run();
     $distFileDir = Config::getDistFileDir();
     $download = new DownloadTask($this->logger, $this->options);
     $targetDir = $download->download($distUrl, $distFileDir, $versionInfo['md5']);
     if (!file_exists($targetDir)) {
         throw new Exception('Download failed.');
     }
     $this->logger->info("Done, please look at: {$targetDir}");
 }
All Usage Examples Of PhpBrew\Tasks\DownloadTask::download
DownloadTask