public function download($targetDir, $version)
    {
        $io = $this->getIO();
        $downloadManager = $this->getComposer()->getDownloadManager();
        $retries = count($this->getPhantomJsVersions());

        while ($retries--) {
            $package = $this->createComposerInMemoryPackage($targetDir, $version);

            try {
                $downloadManager->download($package, $targetDir, false);
                return true;
            } catch (TransportException $e) {
                if ($e->getStatusCode() === 404) {
                    $version = $this->getLowerVersion($version);
                    $io->warning('Retrying the download with a lower version number: "' . $version . '"');
                } else {
                    $message = $e->getMessage();
                    $code = $e->getStatusCode();
                    $io->error(PHP_EOL . '<error>TransportException: "' . $message . '". HTTP status code: ' . $code . '</error>');
                    return false;
                }
            } catch (\Exception $e) {
                $message = $e->getMessage();
                $io->error(PHP_EOL . '<error>While downloading version ' . $version . ' the following error accoured: ' . $message . '</error>');
                return false;
            }
        }
    }
public function download($targetDir, $version)
    {
        $io = $this->getIO();
        $downloadManager = $this->getComposer()->getDownloadManager();
        $retries = count($this->getPhantomJsVersions());

        while ($retries--) {
            $package = $this->createComposerInMemoryPackage($targetDir, $version);

            try {
                $downloadManager->download($package, $targetDir, false);
                return true;
            } catch (TransportException $e) {
                if ($e->getStatusCode() === 404) {
                    $version = $this->getLowerVersion($version);
                    $io->warning('Retrying the download with a lower version number: "' . $version . '"');
                } else {
                    $message = $e->getMessage();
                    $code = $e->getStatusCode();
                    $io->error(PHP_EOL . '<error>TransportException: "' . $message . '". HTTP status code: ' . $code . '</error>');
                    return false;
                }
            } catch (\Exception $e) {
                $message = $e->getMessage();
                $io->error(PHP_EOL . '<error>While downloading version ' . $version . ' the following error accoured: ' . $message . '</error>');
                return false;
            }
        }
    }
public function download ( $ targetDir , $ version ) { $ io = $ this -> getIO ( ) ; $ downloadManager = $ this -> getComposer ( ) -> getDownloadManager ( ) ; $ retries = count ( $ this -> getPhantomJsVersions ( ) ) ; while ( $ retries -- ) { $ package = $ this -> createComposerInMemoryPackage ( $ targetDir , $ version ) ; try { $ downloadManager -> download ( $ package , $ targetDir , false ) ; return true ; } catch ( TransportException $ e ) { if ( $ e -> getStatusCode ( ) === 404 ) { $ version = $ this -> getLowerVersion ( $ version ) ; $ io -> warning ( 'Retrying the download with a lower version number: "' . $ version . '"' ) ; } else { $ message = $ e -> getMessage ( ) ; $ code = $ e -> getStatusCode ( ) ; $ io -> error ( PHP_EOL . '<error>TransportException: "' . $ message . '". HTTP status code: ' . $ code . '</error>' ) ; return false ; } } catch ( \ Exception $ e ) { $ message = $ e -> getMessage ( ) ; $ io -> error ( PHP_EOL . '<error>While downloading version ' . $ version . ' the following error accoured: ' . $ message . '</error>' ) ; return false ; } } }
The main download function.

The package to download is created on the fly.
For downloading Composer\DownloadManager is used.
Downloads are automatically retried with a lower version number,
when the resource it not found (404).

@param string $targetDir
@param string $version
@return boolean
The main download function .