send(); } catch (Http\Exception\RuntimeException $e) { return false; } if (!$response->isSuccess()) { return false; } return $response->getBody(); } /** * Get the latest version from Github * * @param Http\Client $httpClient Configured HTTP client * @return string|null API response or false on error */ protected static function getLatestFromGithub(Http\Client $httpClient = null) { $url = 'https://api.github.com/repos/zendframework/zf2/git/refs/tags/release-'; if ($httpClient === null) { $context = stream_context_create( array( 'http' => array( 'user_agent' => sprintf('Zend-Version/%s', self::VERSION), ), ) ); $apiResponse = file_get_contents($url, false, $context); } else { $request = new Http\Request(); $request->setUri($url); $httpClient->setRequest($request); $apiResponse = self::getApiResponse($httpClient); } if (!$apiResponse) { return false; } $decodedResponse = Json::decode($apiResponse, 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-' }, $decodedResponse); // Fetch the latest version number from the array return array_reduce($tags, function ($a, $b) { return version_compare($a, $b, '>') ? $a : $b; }); } /** * Get the latest version from framework.zend.com * * @param Http\Client $httpClient Configured HTTP client * @return string|null API response or false on error */ protected static function getLatestFromZend(Http\Client $httpClient = null) { $url = 'http://framework.zend.com/api/zf-version?v=2'; if ($httpClient === null) { $apiResponse = file_get_contents($url); } else { $request = new Http\Request(); $request->setUri($url); $httpClient->setRequest($request); $apiResponse = self::getApiResponse($httpClient); } if (!$apiResponse) { return false; } return $apiResponse; } }