Hirak\Prestissimo\Prefetcher::fetchAllFromOperations PHP Method

fetchAllFromOperations() public method

public fetchAllFromOperations ( Composer\IO\IOInterface $io, Composer\Config $config, array $ops )
$io Composer\IO\IOInterface
$config Composer\Config
$ops array
    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);
        }
    }

Usage Example

Exemplo n.º 1
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);
 }
All Usage Examples Of Hirak\Prestissimo\Prefetcher::fetchAllFromOperations