コード例 #1
0
ファイル: Version.php プロジェクト: alab1001101/zf2
 /**
  * Fetches the version of the latest stable release
  *
  * @link http://framework.zend.com/download/latest
  * @return string
  */
 public static function getLatest()
 {
     if (null === self::$latestVersion) {
         self::$latestVersion = 'not available';
         $handle = fopen('http://framework.zend.com/api/zf-version', 'r');
         if (false !== $handle) {
             self::$latestVersion = stream_get_contents($handle);
             fclose($handle);
         }
     }
     return self::$latestVersion;
 }
コード例 #2
0
ファイル: Version.php プロジェクト: robertodormepoco/zf2
 /**
  * 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;
 }