Skip to content

Instantly share code, notes, and snippets.

@rogeriopradoj
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rogeriopradoj/9025851 to your computer and use it in GitHub Desktop.
Save rogeriopradoj/9025851 to your computer and use it in GitHub Desktop.
url for downloading a PHP 5 version release - for using with https://github.com/CHH/php-build/commit/226802e28591287c11b240943876d21b03aec2f4#
<?php
/**
* returns url for downloading a PHP 5 version release
* Check if the release is on museum.php.net, otherwise, use distributions url
*
* @param string $version format X.Y.Z
* @return string url
*/
function urlRelease($version)
{
$urlDistribution = 'http://www.php.net/distributions/php-{version}.tar.bz2';
$urlMuseum = 'http://museum.php.net/php5/php-{version}.tar.bz2';
$urlApiReleases = 'http://www.php.net/releases/index.php?serialize=1&version=5.5.6&max=1000';
$listReleases = unserialize(file_get_contents($urlApiReleases));
if (isset($listReleases[$version]['museum'])) {
return str_replace('{version}', $version, $urlMuseum);
}
return str_replace('{version}', $version, $urlDistribution);
}
<?php
$releases = [
'5.5.9',
'5.4.0',
];
foreach ($releases as $version) {
printf('Version: %s - Url: %s <br>', $version, urlRelease($version));
}
--TEST--
Release out of museum
--FILE--
<?php echo urlRelease('5.5.9'); ?>
--EXPECT--
http://www.php.net/distributions/php-5.5.9.tar.bz2
--TEST--
Release in museum
--FILE--
<?php echo urlRelease('5.4.0'); ?>
--EXPECT--
http://museum.php.net/php5/php-5.4.0.tar.bz2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment