Ejemplo n.º 1
0
 /**
  * @param IO\IOInterface $io
  * @param Config $config
  * @param Operation\OperationInterface[] $ops
  */
 public function fetchAllFromOperations(IO\IOInterface $io, Config $config, array $ops)
 {
     $cachedir = rtrim($config->get('cache-files-dir'), '\\/');
     $requests = array();
     foreach ($ops as $op) {
         switch ($op->getJobType()) {
             case 'install':
                 $p = $op->getPackage();
                 break;
             case 'update':
                 $p = $op->getTargetPackage();
                 break;
             default:
                 continue 2;
         }
         $url = $this->getUrlFromPackage($p);
         if (!$url) {
             continue;
         }
         $destination = $cachedir . DIRECTORY_SEPARATOR . FileDownloaderDummy::getCacheKeyCompat($p, $url);
         if (file_exists($destination)) {
             continue;
         }
         $useRedirector = (bool) preg_match('%^(?:https|git)://github\\.com%', $p->getSourceUrl());
         try {
             $request = new CopyRequest($url, $destination, $useRedirector, $io, $config);
             $requests[] = $request;
         } catch (FetchException $e) {
             // do nothing
         }
     }
     if (count($requests) > 0) {
         $this->fetchAll($io, $requests);
     }
 }
Ejemplo n.º 2
0
 public function testFetchAllWithInstallButFileExists()
 {
     list($opp, $pp) = $this->createProphecies();
     $pp->getName()->willReturn('');
     $pp->getDistType()->willReturn('html');
     $pp->getDistUrl()->willReturn('http://example.com/');
     $pp->getDistMirrors()->willReturn(array());
     $pp->getSourceUrl()->willReturn('git://uso800');
     $path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . FileDownloaderDummy::getCacheKeyCompat($pp->reveal(), 'http://example.com/');
     $fp = fopen($path, 'wb');
     $opp->getPackage()->willReturn($pp->reveal())->shouldBeCalled();
     $fetcher = new Prefetcher();
     $fetcher->fetchAllFromOperations($this->iop->reveal(), $this->configp->reveal(), array($opp->reveal()));
     fclose($fp);
     unlink($path);
 }