Skip to content

Instantly share code, notes, and snippets.

@roderik
Created March 10, 2012 09:46
Show Gist options
  • Save roderik/2010997 to your computer and use it in GitHub Desktop.
Save roderik/2010997 to your computer and use it in GitHub Desktop.
A small snippet to find the latest stable release of Symfony 2
<?php
$githubUser = 'symfony';
$githubRepo = 'symfony';
// Get GitHub JSON request
$githubUrl = 'http://github.com/api/v2/json/repos/show/'.$githubUser.'/'.$githubRepo.'/tags';
$githubJSONResponse = file_get_contents($githubUrl);
// Convert it to a PHP object
$githubResponseArray = json_decode($githubJSONResponse, true);
$tagList = array_keys($githubResponseArray["tags"]);
// Filter out non final tags
$filteredTagList = array_filter($tagList, "tagfilter");
function tagfilter($tag) {
return !stripos($tag, "-") && !stripos($tag, "PR") && !stripos($tag, "BETA") && stripos($tag, "v2.0") === 0;
}
// Sort tags
natcasesort($filteredTagList);
// The first one is the last stable release for Symfony 2
$reverseFilteredTagList = array_reverse($filteredTagList);
echo $reverseFilteredTagList[0];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment