Example #1
0
 private function downloadPackage(Package $package)
 {
     $url = $package->getUrl();
     preg_match('/\\/(php_manual.*)\\//U', $url, $matches);
     $filePath = $this->getTmpDir() . DIRECTORY_SEPARATOR . $matches[1];
     @mkdir(dirname($filePath), 0777, true);
     $bar = $this->createProgressBar();
     $bar->setMessage('Downloading <comment>' . $package->getUrl() . '</comment> to <comment>' . $filePath . '</comment>');
     $bar->start();
     $package->download($filePath, function ($r, $downloadSize, $downloaded) use($bar) {
         if ($downloadSize > 0) {
             $bar->setProgress(round($downloaded / $downloadSize * 100));
         }
     });
     $bar->finish();
     $this->output->writeln('');
     if (0 == filesize($filePath)) {
         $this->output->writeln('<error>Download failed. Please, check selected mirror site.</error>');
     }
 }