public static function findLatestPhpVersion($version = null)
{
$foundVersion = false;
$buildDir = Config::getBuildDir();
$hasPrefix = self::startsWith($version, 'php-');
if (is_dir($buildDir)) {
if ($hasPrefix == true) {
$version = str_replace('php-', '', $version);
}
$fp = opendir($buildDir);
if ($fp !== false) {
while ($file = readdir($fp)) {
if ($file === '.' || $file === '..' || is_file($buildDir . DIRECTORY_SEPARATOR . $file)) {
continue;
}
$curVersion = strtolower(preg_replace('/^[\\D]*-/', '', $file));
if (self::startsWith($curVersion, $version) && version_compare($curVersion, $foundVersion, '>=')) {
$foundVersion = $curVersion;
if (version_compare($foundVersion, $version, '=')) {
break;
}
}
}
closedir($fp);
}
if ($hasPrefix == true && $foundVersion !== false) {
$foundVersion = 'php-' . $foundVersion;
}
}
return $foundVersion;
}