Example #1
0
 /**
  * Retrieve the current version available remotely.
  *
  * @param Updater $updater
  * @return string|bool
  */
 public function getCurrentRemoteVersion(Updater $updater)
 {
     /** Switch remote request errors to HttpRequestExceptions */
     set_error_handler(array($updater, 'throwHttpRequestException'));
     $packageUrl = $this->getApiUrl();
     $package = json_decode(humbug_get_contents($packageUrl), true);
     restore_error_handler();
     if (null === $package || json_last_error() !== JSON_ERROR_NONE) {
         throw new JsonParsingException('Error parsing JSON package data' . (function_exists('json_last_error_msg') ? ': ' . json_last_error_msg() : ''));
     }
     $versions = array_keys($package['package']['versions']);
     $versionParser = new VersionParser($versions);
     if ($this->getStability() === self::STABLE) {
         $this->remoteVersion = $versionParser->getMostRecentStable();
     } elseif ($this->getStability() === self::UNSTABLE) {
         $this->remoteVersion = $versionParser->getMostRecentUnstable();
     } else {
         $this->remoteVersion = $versionParser->getMostRecentAll();
     }
     /**
      * Setup remote URL if there's an actual version to download
      */
     if (!empty($this->remoteVersion)) {
         $this->remoteUrl = $this->getDownloadUrl($package);
     }
     return $this->remoteVersion;
 }
 public function testCanSetRequestHeaders()
 {
     humbug_set_headers(array('Accept-Language: da', 'User-Agent: Humbug'));
     $out = humbug_get_contents('http://myhttp.info/');
     $this->assertEquals(1, preg_match('%' . preg_quote('<td>Accept language</td><td>da</td>') . '%', $out));
     $this->assertEquals(1, preg_match('%' . preg_quote('<td>User agent</td><td>Humbug</td>') . '%', $out));
 }
Example #3
0
 private function checkNewerVersion()
 {
     if (self::VERSION === '@' . 'package_version' . '@') {
         return true;
     }
     $content = humbug_get_contents('https://pixelpolishers.github.com/resolver/resolver.phar.version');
     return substr($content, 0, 40) !== self::VERSION;
 }
 private function checkNewerVersion()
 {
     // Splitted up the version string because we don't want it to be parsed when building :)
     if (PHP_VERSION_ID < 50600 || self::VERSION === '@' . 'package_version' . '@') {
         return false;
     }
     $content = humbug_get_contents('https://pixelpolishers.github.com/resolver/resolver-builder.phar.version');
     return substr($content, 0, 40) !== self::VERSION;
 }
Example #5
0
 /**
  * Retrieve the current version available remotely.
  *
  * @param Updater $updater
  * @return string|bool
  */
 public function getCurrentRemoteVersion(Updater $updater)
 {
     /** Switch remote request errors to HttpRequestExceptions */
     set_error_handler(array($updater, 'throwHttpRequestException'));
     $version = humbug_get_contents($this->getVersionUrl());
     restore_error_handler();
     if (false === $version) {
         throw new HttpRequestException(sprintf('Request to URL failed: %s', $this->getVersionUrl()));
     }
     if (empty($version)) {
         throw new HttpRequestException('Version request returned empty response.');
     }
     if (!preg_match('%^[a-z0-9]{40}%', $version, $matches)) {
         throw new HttpRequestException('Version request returned incorrectly formatted response.');
     }
     return $matches[0];
 }
Example #6
0
 /**
  * Retrieve the current version available remotely.
  *
  * @param Updater $updater
  * 
  * @return string
  */
 public function getCurrentRemoteVersion(Updater $updater)
 {
     /* Switch remote request errors to HttpRequestExceptions */
     set_error_handler(array($updater, 'throwHttpRequestException'));
     $versions = json_decode(humbug_get_contents(self::MANIFEST), true);
     restore_error_handler();
     if (false === $versions) {
         throw new HttpRequestException(sprintf('Request to URL failed: %s', self::MANIFEST));
     }
     $versionParser = new VersionParser($versions);
     if ($this->getStability() === self::STABLE) {
         return $versionParser->getMostRecentStable();
     }
     if ($this->getStability() === self::UNSTABLE) {
         return $versionParser->getMostRecentUnstable();
     }
     return $versionParser->getMostRecentAll();
 }
Example #7
0
 /**
  * Downloads a file.
  *
  * @param string $url The URL of the file to download.
  *
  * @return string The downloaded file body.
  */
 public function download($url)
 {
     humbug_set_headers($this->headers);
     $result = humbug_get_contents($url);
     if ($result && extension_loaded('zlib')) {
         $decode = false;
         foreach (humbug_get_headers() as $header) {
             if (preg_match('{^content-encoding: *gzip *$}i', $header)) {
                 $decode = true;
                 continue;
             } elseif (preg_match('{^HTTP/}i', $header)) {
                 $decode = false;
             }
         }
         if ($decode) {
             $result = version_compare(PHP_VERSION, '5.4.0', '>=') ? zlib_decode($result) : file_get_contents('compress.zlib://data:application/octet-stream;base64,' . base64_encode($result));
             if (!$result) {
                 throw new RuntimeException('Failed to decode zlib stream');
             }
         }
     }
     return $result;
 }