Download the remote Phar file.

@param Updater $updater
@return void
15975
public function download(Updater $updater)
    {
        /** Switch remote request errors to HttpRequestExceptions */
        set_error_handler(array($updater, 'throwHttpRequestException'));
        $result = get_contents($this->getPharUrl());
        restore_error_handler();
        if (false === $result) {
            throw new HttpRequestException(sprintf(
                'Request to URL failed: %s', $this->getPharUrl()
            ));
        }

        file_put_contents($updater->getTempPharFile(), $result);
    }
599778
public function handleUpdateMajorInfo(UpdateMajorInfo $updateMajorInfo)
    {

        /** @var Place $place */
        $place = $this->offerRepository->load($updateMajorInfo->getItemId());

        $place->updateMajorInfo(
            $updateMajorInfo->getTitle(),
            $updateMajorInfo->getEventType(),
            $updateMajorInfo->getAddress(),
            $updateMajorInfo->getCalendar(),
            $updateMajorInfo->getTheme()
        );

        $this->offerRepository->save($place);

    }
577234
protected function _downloadUpdate($updateUrl, $updateFile)
    {
        $this->log->addInfo(sprintf('Downloading update "%s" to "%s"', $updateUrl, $updateFile));
        if (function_exists('curl_version') && $this->_isValidUrl($updateUrl)) {
            $update = $this->_downloadCurl($updateUrl);
            if ($update === false) {
                return false;
            }
        } elseif (ini_get('allow_url_fopen')) {
            // TODO: Throw exception on error
            $update = @file_get_contents($updateUrl, false, $this->_useBasicAuth());

            if ($update === false) {
                $this->log->addError(sprintf('Could not download update "%s"!', $updateUrl));

                throw new DownloadException($updateUrl);
            }
        } else {
            throw new \Exception('No valid download method found!');
        }

        $handle = fopen($updateFile, 'w');
        if (!$handle) {
            $this->log->addError(sprintf('Could not open file handle to save update to "%s"!', $updateFile));

            return false;
        }

        if (!fwrite($handle, $update)) {
            $this->log->addError(sprintf('Could not write update to file "%s"!', $updateFile));
            fclose($handle);

            return false;
        }

        fclose($handle);

        return true;
    }
985347
public function remote_install( $headers, $install ) {
		$install['download_link']               = ! empty( $headers['uri'] ) ? $headers['uri'] : $headers['original'];
		$install['github_updater_install_repo'] = $install['zipfile_slug'];

		return $install;
	}
107715
private function download(RemotePackageEntity $remotePackage)
    {
        $temp = $this->app->make(VolatileDirectory::class);
        /* @var VolatileDirectory $temp */
        $zipFilename = $temp->getPath() . '/downloaded.zip';
        $this->httpClient->reset();
        $this->httpClient->setOptions([
            'storeresponse' => false,
            'outputstream' => $zipFilename,
        ]);
        $request = new Request();

        if (($header = (string) getenv('CT_REMOTEPACKAGE_HEADER')) &&
            $value = (string) getenv('CT_REMOTEPACKAGE_HEADER_VALUE')) {
            $request->getHeaders()->addHeaderLine($header, $value);
        }
        $request->setMethod('GET')->setUri($remotePackage->getArchiveUrl());
        $response = $this->httpClient->send($request);
        $this->httpClient->reset();
        $streamHandle = ($response instanceof \Zend\Http\Response\Stream) ? $response->getStream() : null;
        if (is_resource($streamHandle)) {
            fclose($streamHandle);
        }
        if ($response->getStatusCode() != 200) {
            $error = t('Failed to download package archive %s v%s: %s (%d)', $remotePackage->getHandle(), $remotePackage->getVersion(), $response->getReasonPhrase(), $response->getStatusCode());
            unset($temp);
            throw new DownloadException($error, $response->getStatusCode());
        }

        $contentEncodingHeader = $response->getHeaders()->get('Content-Encoding');
        if (!empty($contentEncodingHeader)) {
            $contentEncoding = trim((string) $contentEncodingHeader->getFieldValue());
            if ($contentEncoding !== '') {
                $decodedZipFilename = $temp->getPath() . '/downloaded-decoded.zip';
                switch (strtolower($contentEncoding)) {
                    case 'gzip':
                        $this->decodeGzip($zipFilename, $decodedZipFilename);
                        break;
                    case 'deflate':
                        $this->decodeDeflate($zipFilename, $decodedZipFilename);
                        break;
                    case 'plainbinary':
                    default:
                        $decodedZipFilename = '';
                        break;
                }
                if ($decodedZipFilename !== '') {
                    $temp->getFilesystem()->delete([$zipFilename]);
                    $zipFilename = $decodedZipFilename;
                }
            }
        }

        $temp->getFilesystem()->makeDirectory($temp->getPath() . '/unzipped');
        $this->zip->unzip($zipFilename, $temp->getPath() . '/unzipped');
        $temp->getFilesystem()->delete([$zipFilename]);

        return $temp;
    }
1112127
private function stable(Updater $updater)
    {
        $updater->setStrategy(Updater::STRATEGY_GITHUB);
        $updater->getStrategy()->setPackageName('nanbando/core');
        $updater->getStrategy()->setPharName('nanbando.phar');
        $updater->getStrategy()->setCurrentLocalVersion('@git_version@');
        $updater->getStrategy()->setStability(GithubStrategy::STABLE);
    }
1250894
protected function addFileToPhar($path, Phar $phar)
    {
        $realPath = realpath($path);

        $content = file_get_contents($realPath);

        $phar->addFromString($realPath, $content);
    }
31161
private function addBinFile($phar)
    {
        $content = file_get_contents(__DIR__ . '/../../bin/ctb');
        $content = preg_replace('{^#!/usr/bin/env php\s*}', '', $content);
        $phar->addFromString('bin/ctb', $content);
    }
522668
public function setUpdater($updater)
    {
        if (!is_string($this->updatedByAttribute) || empty($this->updatedByAttribute)) {
            return false;
        }
        if ($updater instanceof $this->hostClass || $updater instanceof \yii\web\IdentityInterface) {
            return $this->{$this->updatedByAttribute} = $updater->getGUID();
        }
        if (is_string($updater) && preg_match(Number::GUID_REGEX, $updater)) {
            return $this->{$this->updatedByAttribute} = Number::guid_bin($updater);
        }
        if (strlen($updater) == 16) {
            return $this->{$this->updatedByAttribute} = $updater;
        }
        return false;
    }
1310459
protected function makePhar()
    {
        $phar = new Phar($this->filePhar, 0, $this->alias);
        $phar->setSignatureAlgorithm(\Phar::SHA1);
        $phar->startBuffering();

        // Adicionar arquivos
        $this->addFiles($phar);

        // Adicionar arquivo bin
        $this->addBinFile($phar);

        // Adicionar Stup
        $this->addStub($phar);

        // Adicionar licenca
        $this->addLicence($phar);

        // Adicionar arquivo de update
        //$this->addUpdateFile($phar);

        // Finalizar phar.
        $phar->stopBuffering();
        unset($phar);
    }
668713
public function build($indexFilePath, \Phar $phar = null, $build = 'dev')
    {
        if (null === $phar) {
            if ($this->stdOut) {
                echo 'Creating Phar using default settings'.PHP_EOL;
            }
            $phar = $this->createDefaultPhar();
        }
        $phar->startBuffering();

        foreach ($this->finders as $finder) {
            foreach ($finder as $file) {
                $this->addFileToPhar($file, $phar);
            }
        }

        foreach ($this->files as $file) {
            $this->addFileToPhar($file, $phar);
        }

        $this->addIndex($phar, $indexFilePath);

        $this->addStub($phar, $build);
        $phar->stopBuffering();
        $phar->compressFiles(\Phar::GZ);

        if ($this->stdOut) {
            echo 'Done!'.PHP_EOL;
        }

        return $this;
    }
889429
public function getCurrentRemoteVersion(Updater $updater)
    {
        $releasesUrl = sprintf(
            self::URL_RELEASES,
            urlencode($this->repositoryOwner),
            urlencode($this->repositoryName)
        );
        $releasesJson = $this->getJsonResource($releasesUrl);
        $releases = json_decode($releasesJson, true);

        if (null === $releases || json_last_error() !== JSON_ERROR_NONE) {
            throw new JsonParsingException(sprintf('Error parsing JSON release data: %s', json_last_error_msg()));
        }

        $indexedReleases = array_combine(array_column($releases, 'tag_name'), $releases);
        $indexedPharReleases = array_filter(
            $indexedReleases,
            function (array $release) {
                if ($release['draft']) {
                    return false;
                }

                $pharAssets = array_filter(
                    $release['assets'],
                    function (array $asset) {
                        return $asset['name'] === $this->releasePharName;
                    }
                );
                $hasPharAsset = count($pharAssets) > 0;

                return $hasPharAsset;
            }
        );

        if (count($indexedPharReleases) === 0) {
            return false;
        }

        $tagNames = array_keys($indexedPharReleases);
        $versionParser = new VersionParser($tagNames);

        if ($this->allowUnstable) {
            $this->remoteVersion = $versionParser->getMostRecentAll();
        } else {
            $this->remoteVersion = $versionParser->getMostRecentStable();
        }

        if (!$this->remoteVersion) {
            return $this->remoteVersion;
        }

        $release = $indexedPharReleases[$this->remoteVersion];
        $pharAssets = array_filter(
            $release['assets'],
            function (array $asset) {
                return $asset['name'] === $this->releasePharName;
            }
        );

        $this->remoteUrl = $pharAssets[0]['url'];

        return $this->remoteVersion;
    }
1022155
public function download($owner, $repo, $ref)
    {
        // local filesystem
        $fs = $this->getFs();
        // projects filesystem
        $pfs = $this->project->getFiles();
        // remote filesystem (repo on github/bitbucket)
        $rfs = $this->remote->getFilesystem($repo, $owner, $ref);

        $files = $rfs->allFiles($this->docPath);
        $files = Arr::without($files, [ $this->indexPath, $this->menuPath ]);
        $total = count($files);

        if ( !$rfs->exists($this->indexPath) )
        {
            return $this->syncer->log('error', 'syncRef could not find the index file', [ $this->indexPath ]);
        }

        if ( !$rfs->exists($this->menuPath) )
        {
            return $this->syncer->log('error', 'syncRef could not find the menu file', [ $this->menuPath ]);
        }

        foreach ( $files as $current => $filePath )
        {
            $destPath = path_relative($filePath, $this->docPath);
            if ( $rfs->exists($filePath) )
            {
                $pfs->put(path_join($ref, $destPath), $rfs->get($filePath));
            }
            $this->getSyncer()->fire('tick.file', [ $current, $total, $filePath, $this->syncer, $this ]);
        }

        // index and menu resolving
        $pfs->put(path_join($ref, 'index.md'), $rfs->get($this->indexPath));
        $pfs->put(path_join($ref, 'menu.yml'), $rfs->get($this->menuPath));

        return $this;
    }
531511
private function getRemoteVersionInfo(Updater $updater)
    {
        $version = $this->getCurrentRemoteVersion($updater);
        if ($version === false) {
            throw new \RuntimeException('No remote versions found');
        }
        $versionInfo = $this->getAvailableVersions();
        if (!isset($versionInfo[$version])) {
            throw new \RuntimeException(sprintf('Failed to find manifest item for version %s', $version));
        }

        return $versionInfo[$version];
    }
231324
public static function release() {
		log::print('Building blob-common.phar…');

		// Define some paths.
		$bin_dir = \dirname(\BOB_ROOT_DIR) . '/bin/';

		// Remove original.
		if (\is_file("{$bin_dir}blob-common.phar")) {
			\unlink("{$bin_dir}blob-common.phar");
		}

		\clearstatcache();

		// Make new.
		$phar = new Phar("{$bin_dir}blob-common.phar", 0);
		$phar->startBuffering();
		$phar->buildFromDirectory(static::$_working_dir);
		$phar->setStub(static::$stub_common);
		$phar->compressFiles(Phar::GZ);
		$phar->stopBuffering();

		// Compile a version release file.
		$out = array(
			'checksum'=>\md5_file("{$bin_dir}blob-common.phar"),
			'date_created'=>\date('c'),
			'size'=>\intval(\filesize("{$bin_dir}blob-common.phar")),
			'url'=>static::COMMON_REMOTE,
		);
		\file_put_contents("{$bin_dir}blob-common.json", \json_encode($out, \JSON_PRETTY_PRINT));

		log::print('Building test.phar…');

		$phar = new Phar("{$bin_dir}test.phar", 0);
		$phar->startBuffering();
		$phar->addFromString('dummy.php', "<?php\n// Comment.");
		$phar->setStub(static::$stub_test);
		$phar->compressFiles(Phar::GZ);
		$phar->stopBuffering();
	}
1188379
def download(self, local, remote):
        
        self.sync(RemoteFile(remote, self.api), LocalFile(local))
258967
public function expand($cleanup = true)
	{
		// Create local tmp copy of the archive that's being expanded
		$temp = Manager::getTempPath($this->getName());
		$this->copy($temp);

		$archive = new \PharData($temp->getAbsolutePath());

		foreach ($archive as $file)
		{
			// Add 7 to the length for the 'phar://' prefix to the file
			$path   = substr($file, strlen($temp->getAbsolutePath()) + 7);
			$entity = Entity::fromPath($this->getParent() . $path, $this->getAdapter());

			if ($entity->isFile())
			{
				// Open
				$item = fopen($file, 'r');

				// Write stream
				$entity->putStream($item);

				// Close
				fclose($item);
			}
			else
			{
				// Create the directory
				$entity->create();
			}
		}

		// Clean up
		$temp->delete();

		return parent::expand($cleanup);
	}