Exemplo n.º 1
0
 /**
  * Fetches the version of the latest stable release.
  *
  * This uses the GitHub API (v3) and only returns refs that begin with
  * 'tags/release-'. Because GitHub returns the refs in alphabetical order,
  * we need to reduce the array to a single value, comparing the version
  * numbers with version_compare().
  *
  * @see http://developer.github.com/v3/git/refs/#get-all-references
  * @link https://api.github.com/repos/zendframework/zf2/git/refs/tags/release-
  * @return string
  */
 public static function getLatest()
 {
     if (null === self::$latestVersion) {
         self::$latestVersion = 'not available';
         $url = 'https://api.github.com/repos/zendframework/zf2/git/refs/tags/release-';
         $apiResponse = Json::decode(file_get_contents($url), Json::TYPE_ARRAY);
         // Simplify the API response into a simple array of version numbers
         $tags = array_map(function ($tag) {
             return substr($tag['ref'], 18);
             // Reliable because we're filtering on 'refs/tags/release-'
         }, $apiResponse);
         // Fetch the latest version number from the array
         self::$latestVersion = array_reduce($tags, function ($a, $b) {
             return version_compare($a, $b, '>') ? $a : $b;
         });
     }
     return self::$latestVersion;
 }
Exemplo n.º 2
0
 /**
  * Fetches the version of the latest stable release.
  *
  * By default, this uses the API provided by framework.zend.com for version
  * retrieval.
  *
  * If $service is set to VERSION_SERVICE_GITHUB, this will use the GitHub
  * API (v3) and only returns refs that begin with * 'tags/release-'.
  * Because GitHub returns the refs in alphabetical order, we need to reduce
  * the array to a single value, comparing the version numbers with
  * version_compare().
  *
  * @see    http://developer.github.com/v3/git/refs/#get-all-references
  * @link   https://api.github.com/repos/zendframework/zf2/git/refs/tags/release-
  * @link   http://framework.zend.com/api/zf-version?v=2
  * @param  string      $service    Version service with which to retrieve the version
  * @param  Http\Client $httpClient HTTP client with which to retrieve the version
  * @return string
  */
 public static function getLatest($service = self::VERSION_SERVICE_ZEND, Http\Client $httpClient = null)
 {
     if (null !== self::$latestVersion) {
         return self::$latestVersion;
     }
     self::$latestVersion = 'not available';
     if (null === $httpClient && !ini_get('allow_url_fopen')) {
         trigger_error(sprintf('allow_url_fopen is not set, and no Zend\\Http\\Client ' . 'was passed. You must either set allow_url_fopen in ' . 'your PHP configuration or pass a configured ' . 'Zend\\Http\\Client as the second argument to %s.', __METHOD__), E_USER_WARNING);
         return self::$latestVersion;
     }
     $response = false;
     if ($service === self::VERSION_SERVICE_GITHUB) {
         $response = self::getLatestFromGithub($httpClient);
     } elseif ($service === self::VERSION_SERVICE_ZEND) {
         $response = self::getLatestFromZend($httpClient);
     } else {
         trigger_error(sprintf('Unknown version service: %s', $service), E_USER_WARNING);
     }
     if ($response) {
         self::$latestVersion = $response;
     }
     return self::$latestVersion;
 }
Exemplo n.º 3
0
 /**
  * Fetches the version of the latest stable release.
  *
  * By Default, this uses the GitHub API (v3) and only returns refs that begin with
  * 'tags/release-'. Because GitHub returns the refs in alphabetical order,
  * we need to reduce the array to a single value, comparing the version
  * numbers with version_compare().
  *
  * If $service is set to VERSION_SERVICE_ZEND this will fall back to calling the
  * classic style of version retreival.
  *
  *
  * @see http://developer.github.com/v3/git/refs/#get-all-references
  * @link https://api.github.com/repos/zendframework/zf2/git/refs/tags/release-
  * @link http://framework.zend.com/api/zf-version?v=2
  * @param string $service Version Service with which to retrieve the version
  * @return string
  */
 public static function getLatest($service = self::VERSION_SERVICE_GITHUB)
 {
     if (null === self::$latestVersion) {
         self::$latestVersion = 'not available';
         if ($service == self::VERSION_SERVICE_GITHUB) {
             $url = 'https://api.github.com/repos/zendframework/zf2/git/refs/tags/release-';
             $apiResponse = Json::decode(file_get_contents($url), Json::TYPE_ARRAY);
             // Simplify the API response into a simple array of version numbers
             $tags = array_map(function ($tag) {
                 return substr($tag['ref'], 18);
                 // Reliable because we're filtering on 'refs/tags/release-'
             }, $apiResponse);
             // Fetch the latest version number from the array
             self::$latestVersion = array_reduce($tags, function ($a, $b) {
                 return version_compare($a, $b, '>') ? $a : $b;
             });
         } elseif ($service == self::VERSION_SERVICE_ZEND) {
             $handle = fopen('http://framework.zend.com/api/zf-version?v=2', 'r');
             if (false !== $handle) {
                 self::$_latestVersion = stream_get_contents($handle);
                 fclose($handle);
             }
         }
     }
     return self::$latestVersion;
 }