PhpBrew\Version::findLatestPatchVersion PHP Method

findLatestPatchVersion() public static method

public static findLatestPatchVersion ( $currentVersion, array $versions )
$versions array
    public static function findLatestPatchVersion($currentVersion, array $versions)
    {
        // Trim 5.4.29 to 5.4
        $va = explode('.', $currentVersion);
        if (count($va) == 3) {
            list($cMajor, $cMinor, $cPatch) = $va;
        } elseif (count($va) == 2) {
            list($cMajor, $cMinor) = $va;
            $cPatch = 0;
        }
        foreach ($versions as $version) {
            list($major, $minor, $patch) = explode('.', $version);
            if ($major == $cMajor && $minor == $cMinor && $patch > $cPatch) {
                $cPatch = $patch;
            }
        }
        return implode('.', array($cMajor, $cMinor, $cPatch));
    }

Usage Example

Beispiel #1
0
 public function testFindLastPatchVersion()
 {
     $ret = Version::findLatestPatchVersion('5.5', array('5.5.26', '5.5.25', '5.5.1'));
     $this->assertEquals('5.5.26', $ret);
 }