示例#1
0
 /**
  * @param \GetOptionKit\OptionSpecCollection $opts
  */
 public function options($opts)
 {
     $opts->add('f|force', 'Force extraction');
     $opts->add('old', 'enable old phps (less than 5.3)');
     $opts->add('mirror:', 'Use mirror specific site.');
     DownloadFactory::addOptionsForCommand($opts);
 }
示例#2
0
 public function download($url, $dir, $md5 = null)
 {
     if (!is_writable($dir)) {
         throw new Exception("Directory is not writable: {$dir}");
     }
     $downloader = DownloadFactory::getInstance($this->logger, $this->options);
     $basename = $downloader->resolveDownloadFileName($url);
     if (!$basename) {
         throw new Exception("Can not parse url: {$url}");
     }
     $targetFilePath = $dir . DIRECTORY_SEPARATOR . $basename;
     if (!$this->options->force && file_exists($targetFilePath)) {
         $this->logger->info('Checking distribution checksum...');
         $md5a = md5_file($targetFilePath);
         if ($md5 && $md5a != $md5) {
             $this->logger->warn("Checksum mismatch: {$md5a} != {$md5}");
             $this->logger->info('Re-Downloading...');
             $downloader->download($url, $targetFilePath);
         } else {
             $this->logger->info('Checksum matched: ' . $md5);
         }
     } else {
         $downloader->download($url, $targetFilePath);
     }
     return $targetFilePath;
 }
示例#3
0
 protected function getPackageXml($packageName, $version)
 {
     $channel = new PeclChannel($this->site);
     $baseUrl = $channel->getRestBaseUrl();
     $url = "{$baseUrl}/r/" . strtolower($packageName);
     $downloader = new CurlDownloader();
     $downloader = DownloadFactory::getInstance($this->logger, $this->options);
     // translate version name into numbers
     if (in_array($version, array('stable', 'latest', 'beta'))) {
         $stabilityTxtUrl = $url . '/' . $version . '.txt';
         if ($ret = $downloader->request($stabilityTxtUrl)) {
             $version = (string) $ret;
         } else {
             throw new Exception("Can not translate stability {$version} into exact version name.");
         }
     }
     $xmlUrl = $url . '/' . $version . '.xml';
     if ($ret = $downloader->request($xmlUrl)) {
         $dom = new DOMDocument('1.0');
         $dom->strictErrorChecking = false;
         $dom->preserveWhiteSpace = false;
         // $dom->resolveExternals = false;
         if (false === $dom->loadXml($ret)) {
             throw new Exception("Error in XMl document: {$url}");
         }
         return $dom;
     }
     return false;
 }
示例#4
0
 /**
  * @param \GetOptionKit\OptionSpecCollection $opts
  */
 public function options($opts)
 {
     $opts->add('m|more', 'Show more older versions');
     $opts->add('o|old', 'List old phps (less than 5.3)');
     $opts->add('u|update', 'Update release list');
     DownloadFactory::addOptionsForCommand($opts);
 }
示例#5
0
 public function execute($branch = 'master')
 {
     global $argv;
     $script = realpath($argv[0]);
     if (!is_writable($script)) {
         throw new Exception("{$script} is not writable.");
     }
     // fetch new version phpbrew
     $this->logger->info("Updating phpbrew {$script} from {$branch}...");
     $url = "https://raw.githubusercontent.com/phpbrew/phpbrew/{$branch}/phpbrew";
     //download to a tmp file first
     $downloader = DownloadFactory::getInstance($this->logger, $this->options, array(DownloadFactory::METHOD_CURL, DownloadFactory::METHOD_WGET));
     //the phar file is large so we prefer the commands rather than extensions.
     $tempFile = $downloader->download($url);
     if ($tempFile === false) {
         throw new RuntimeException('Update Failed', 1);
     }
     chmod($tempFile, 0755);
     //todo we can check the hash here in order to make sure we have download the phar successfully
     //move the tmp file to executable path
     $code = rename($tempFile, $script);
     if ($code === false) {
         //fallback to system move
         $code = system("mv -f {$tempFile}, {$script}");
         if (!$code == 0) {
             throw new RuntimeException('Update Failed', 3);
         }
     }
     $this->logger->info('Version updated.');
     system($script . ' init');
     system($script . ' --version');
 }
示例#6
0
 private function _test($downloader)
 {
     $instance = DownloadFactory::getInstance($this->logger, new OptionResult(), $downloader);
     if ($instance->hasSupport(false)) {
         $actualFilePath = tempnam(Config::getTempFileDir(), '');
         $instance->download('http://httpbin.org/', $actualFilePath);
         $this->assertFileExists($actualFilePath);
     } else {
         $this->markTestSkipped();
     }
 }
示例#7
0
 public function execute($appName)
 {
     $apps = AppStore::all();
     if (!isset($apps[$appName])) {
         throw new Exception("App {$appName} not found.");
     }
     $app = $apps[$appName];
     $targetDir = Config::getRoot() . DIRECTORY_SEPARATOR . 'bin';
     $target = $targetDir . DIRECTORY_SEPARATOR . $app['as'];
     DownloadFactory::getInstance($this->logger, $this->options)->download($app['url'], $target);
     $this->logger->info('Changing permissions to 0755');
     if ($mod = $this->options->chmod) {
         chmod($target, octdec($mod));
     } else {
         chmod($target, 0755);
     }
     $this->logger->info("Downloaded at {$target}");
 }
示例#8
0
 public function options($opts)
 {
     $opts->add('o|old', 'List old phps (less than 5.3)');
     $opts->add('official', 'Unserialize release information from official site (using `unserialize` function).');
     DownloadFactory::addOptionsForCommand($opts);
 }
示例#9
0
 /**
  * @param \GetOptionKit\OptionCollection $opts
  */
 public function options($opts)
 {
     $opts->add('test', 'Run tests after the installation.');
     $opts->add('name:', 'The name of the installation. By default the installed path is equal to the release version name (php-5.x.x), however you can specify a custom name instead of the default `php-5.x.x`. For example, `myphp-5.3.2-dbg`')->valueName('name');
     $opts->add('mirror:', 'Use specified mirror site. phpbrew will download the files from [mirror]/distributions/*');
     $opts->add('post-clean', 'Run make clean after the installation.');
     $opts->add('production', 'Use production configuration file. this installer will copy the php-production.ini into the etc directory.');
     $opts->add('build-dir:', 'Specify the build directory. ' . 'the distribution tarball will be extracted to the directory you specified ' . 'instead of $PHPBREW_ROOT/build/{name}.')->isa('dir');
     $opts->add('root', 'specify phpbrew root instead of PHPBREW_ROOT');
     $opts->add('home', 'specify phpbrew home instead of PHPBREW_HOME');
     $opts->add('no-config-cache', 'do not use config.cache for configure script.');
     $opts->add('no-clean', 'Do not clean previously compiled objects before building PHP. ' . 'By default phpbrew will run `make clean` before running the configure script ' . 'to ensure everything is cleaned up.');
     $opts->add('no-patch', 'Do not apply any patch');
     $opts->add('no-configure', 'Do not run configure script');
     $opts->add('no-install', 'Do not install, just run build the target');
     $opts->add('n|nice:', 'Runs build processes at an altered scheduling priority. The priority can be adjusted over a range of -20 (the highest) to 20 (the lowest).')->valueName('priority');
     $opts->add('patch+:', 'Apply patch before build.')->isa('file');
     $opts->add('old', 'Install phpbrew incompatible phps (< 5.3)');
     $opts->add('user-config', 'Allow users create their own config file (php.ini or extension config init files)');
     DownloadFactory::addOptionsForCommand($opts);
     $opts->add('f|force', 'Force the installation (redownloads source).')->defaultValue(false);
     $opts->add('d|dryrun', 'Do not build, but run through all the tasks.');
     $opts->add('like:', 'Inherit variants from an existing build. This option would require an existing build directory from the {version}.')->valueName('version');
     $opts->add('j|jobs:', 'Specifies the number of jobs to run build simultaneously (make -jN).')->valueName('concurrent job number');
     $opts->add('stdout', 'Outputs install logs to stdout.');
     $opts->add('sudo', 'sudo to run install command.');
 }
示例#10
0
 /**
  * @param \GetOptionKit\OptionSpecCollection $opts
  */
 public function options($opts)
 {
     DownloadFactory::addOptionsForCommand($opts);
 }
示例#11
0
 private static function downloadReleaseListFromOfficialSite($version, OptionResult $options = null)
 {
     $max = $options && $options->old ? 1000 : 100;
     $url = "https://secure.php.net/releases/index.php?json&version={$version}&max={$max}";
     $file = DownloadFactory::getInstance(Logger::getInstance(), $options)->download($url);
     $json = file_get_contents($file);
     return json_decode($json, true);
 }
示例#12
0
 /**
  * @param \GetOptionKit\OptionSpecCollection $opts
  */
 public function options($opts)
 {
     $opts->add('pecl', 'Try to download from pecl even when ext source is bundled with php-src.');
     $opts->add('redownload', 'Force to redownload extension source even if it is already available.');
     DownloadFactory::addOptionsForCommand($opts);
 }