Наследование: extends CLIFramework\Application
Пример #1
0
 public function run($args, $version, $buffer = false)
 {
     if ($buffer) {
         ob_start();
     }
     $this->runUse($version);
     $console = new Console();
     array_unshift($args, 'phpbrew');
     $console->run($args);
     if ($buffer) {
         return ob_end_clean();
     }
 }
Пример #2
0
 public function knownReleases(Provider $provider)
 {
     $url = $provider->buildKnownReleasesUrl();
     if (extension_loaded('curl')) {
         $curlVersionInfo = curl_version();
         $curlOptions = array(CURLOPT_USERAGENT => 'curl/' . $curlVersionInfo['version']);
         $downloader = new CurlDownloader();
         $downloader->setProgressHandler(new ProgressBar());
         $console = Console::getInstance();
         if (!$console->options->{'no-progress'}) {
             $downloader->setProgressHandler(new ProgressBar());
         }
         if ($this->options) {
             if ($proxy = $this->options->{'http-proxy'}) {
                 $downloader->setProxy($proxy);
             }
             if ($proxyAuth = $this->options->{'http-proxy-auth'}) {
                 $downloader->setProxyAuth($proxyAuth);
             }
         }
         $info = $downloader->request($url, array(), $curlOptions);
     } else {
         $info = file_get_contents($url);
     }
     return $provider->parseKnownReleasesResponse($info);
 }
Пример #3
0
 public function setupApplication()
 {
     $console = Console::getInstance();
     $console->getLogger()->setQuiet();
     $console->getFormatter()->preferRawOutput();
     return $console;
 }
Пример #4
0
 public function setUp()
 {
     parent::setUp();
     $this->previousPhpBrewRoot = getenv('PHPBREW_ROOT');
     $this->previousPhpBrewHome = getenv('PHPBREW_HOME');
     // <env name="PHPBREW_ROOT" value=".phpbrew"/>
     // <env name="PHPBREW_HOME" value=".phpbrew"/>
     // already setup in phpunit.xml, but it seems don't work.
     putenv('PHPBREW_ROOT=' . getcwd() . '/.phpbrew');
     putenv('PHPBREW_HOME=' . getcwd() . '/.phpbrew');
     if ($options = \PhpBrew\Console::getInstance()->options) {
         $option = new Option('no-progress');
         $option->setValue(true);
         $options->set('no-progress', $option);
     }
 }
Пример #5
0
 /**
  * @param string $url
  *
  * @return bool|string
  *
  * @throws \RuntimeException
  */
 public function download($url, $targetFilePath)
 {
     $this->logger->info("===> Downloading from {$url}");
     if ($this->isCurlExtensionAvailable()) {
         $this->logger->debug('---> Found curl extension, using CurlDownloader');
         $downloader = new CurlDownloader();
         $seconds = $this->options->{'connect-timeout'};
         if ($seconds || ($seconds = getenv('CONNECT_TIMEOUT'))) {
             $downloader->setConnectionTimeout($seconds);
         }
         if ($proxy = $this->options->{'http-proxy'}) {
             $downloader->setProxy($proxy);
         }
         if ($proxyAuth = $this->options->{'http-proxy-auth'}) {
             $downloader->setProxyAuth($proxyAuth);
         }
         // TODO: Get current instance instead of singleton to improve testing output
         $console = Console::getInstance();
         if (!$console->options->{'no-progress'} && $this->logger->getLevel() > 2) {
             $downloader->setProgressHandler(new ProgressBar());
         }
         $binary = $downloader->request($url);
         if (false === file_put_contents($targetFilePath, $binary)) {
             throw new RuntimeException("Can't write file {$targetFilePath}");
         }
     } else {
         $this->logger->debug('Curl extension not found, fallback to wget or curl');
         // check for wget or curl for downloading the php source archive
         if ($this->isWgetCommandAvailable()) {
             $quiet = $this->logger->isQuiet() ? '--quiet' : '';
             Utils::system("wget --no-check-certificate -c {$quiet} -O" . $targetFilePath . ' ' . $url);
         } elseif ($this->isCurlCommandAvailable()) {
             $silent = $this->logger->isQuiet() ? '--silent ' : '';
             Utils::system("curl -C - -L {$silent} -o" . $targetFilePath . ' ' . $url);
         } else {
             throw new RuntimeException("Download failed - neither wget nor curl was found");
         }
     }
     // Verify the downloaded file.
     if (!file_exists($targetFilePath)) {
         throw new RuntimeException("Download failed.");
     }
     $this->logger->info("===> {$targetFilePath} downloaded.");
     return $targetFilePath;
     // return the filename
 }
Пример #6
0
 private static function downloadReleaseListFromOfficialSite($version, OptionResult $options = null)
 {
     if (!extension_loaded('openssl')) {
         throw new Exception('openssl extension not found, to download releases file you need openssl.');
     }
     $max = $options && $options->old ? 1000 : 100;
     $url = "https://secure.php.net/releases/index.php?json&version={$version}&max={$max}";
     if (extension_loaded('curl')) {
         $downloader = new CurlDownloader();
         $downloader->setProgressHandler(new ProgressBar());
         if (!Console::getInstance()->options->{'no-progress'}) {
             $downloader->setProgressHandler(new ProgressBar());
         }
         if ($options) {
             $seconds = $options->{'connect-timeout'};
             if ($seconds || ($seconds = getenv('CONNECT_TIMEOUT'))) {
                 $downloader->setConnectionTimeout($seconds);
             }
             if ($proxy = $options->{'http-proxy'}) {
                 $downloader->setProxy($proxy);
             }
             if ($proxyAuth = $options->{'http-proxy-auth'}) {
                 $downloader->setProxyAuth($proxyAuth);
             }
         }
         $json = $downloader->request($url);
     } else {
         $json = file_get_contents($url);
     }
     $obj = json_decode($json, true);
     return $obj;
 }
Пример #7
0
 public static function buildReleaseListFromOfficialSite(OptionResult $options = null)
 {
     if (!extension_loaded('openssl')) {
         throw new Exception('openssl extension not found, to download releases file you need openssl.');
     }
     $max = $options && $options->old ? 1000 : 100;
     $url = "https://php.net/releases/index.php?json&version=5&max={$max}";
     if (extension_loaded('curl')) {
         $downloader = new CurlDownloader();
         $downloader->setProgressHandler(new ProgressBar());
         if (!Console::getInstance()->options->{'no-progress'}) {
             $downloader->setProgressHandler(new ProgressBar());
         }
         if ($options) {
             $seconds = $options->{'connect-timeout'};
             if ($seconds || ($seconds = getenv('CONNECT_TIMEOUT'))) {
                 $downloader->setConnectionTimeout($seconds);
             }
             if ($proxy = $options->{'http-proxy'}) {
                 $downloader->setProxy($proxy);
             }
             if ($proxyAuth = $options->{'http-proxy-auth'}) {
                 $downloader->setProxyAuth($proxyAuth);
             }
         }
         $json = $downloader->request($url);
     } else {
         $json = file_get_contents($url);
     }
     $obj = json_decode($json, true);
     $releaseVersions = array();
     foreach ($obj as $k => $v) {
         if (preg_match('/^(\\d+)\\.(\\d+)\\./', $k, $matches)) {
             list($o, $major, $minor) = $matches;
             $release = array('version' => $k);
             if (isset($v['announcement']['English'])) {
                 $release['announcement'] = 'http://php.net' . $v['announcement']['English'];
             }
             if (isset($v['date'])) {
                 $release['date'] = $v['date'];
             }
             foreach ($v['source'] as $source) {
                 if (isset($source['filename']) && preg_match('/\\.tar\\.bz2$/', $source['filename'])) {
                     $release['filename'] = $source['filename'];
                     $release['name'] = $source['name'];
                     if (isset($source['md5'])) {
                         $release['md5'] = $source['md5'];
                     }
                     if (isset($source['date'])) {
                         $release['date'] = $source['date'];
                     }
                 }
             }
             $releaseVersions["{$major}.{$minor}"][$k] = $release;
         }
     }
     foreach ($releaseVersions as $key => &$versions) {
         uksort($releaseVersions[$key], function ($a, $b) {
             return version_compare($b, $a);
         });
     }
     return $releaseVersions;
 }