Last active
August 29, 2015 13:56
-
-
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#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$releases = [ | |
'5.5.9', | |
'5.4.0', | |
]; | |
foreach ($releases as $version) { | |
printf('Version: %s - Url: %s <br>', $version, urlRelease($version)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--TEST-- | |
Release out of museum | |
--FILE-- | |
<?php echo urlRelease('5.5.9'); ?> | |
--EXPECT-- | |
http://www.php.net/distributions/php-5.5.9.tar.bz2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--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