PMA\libraries\VersionInformation::versionToInt PHP Method

versionToInt() public method

Calculates numerical equivalent of phpMyAdmin version string
public versionToInt ( string $version ) : mixed
$version string version
return mixed false on failure, integer on success
    public function versionToInt($version)
    {
        $parts = explode('-', $version);
        if (count($parts) > 1) {
            $suffix = $parts[1];
        } else {
            $suffix = '';
        }
        $parts = explode('.', $parts[0]);
        $result = 0;
        if (count($parts) >= 1 && is_numeric($parts[0])) {
            $result += 1000000 * $parts[0];
        }
        if (count($parts) >= 2 && is_numeric($parts[1])) {
            $result += 10000 * $parts[1];
        }
        if (count($parts) >= 3 && is_numeric($parts[2])) {
            $result += 100 * $parts[2];
        }
        if (count($parts) >= 4 && is_numeric($parts[3])) {
            $result += 1 * $parts[3];
        }
        if (!empty($suffix)) {
            $matches = array();
            if (preg_match('/^(\\D+)(\\d+)$/', $suffix, $matches)) {
                $suffix = $matches[1];
                $result += intval($matches[2]);
            }
            switch ($suffix) {
                case 'pl':
                    $result += 60;
                    break;
                case 'rc':
                    $result += 30;
                    break;
                case 'beta':
                    $result += 20;
                    break;
                case 'alpha':
                    $result += 10;
                    break;
                case 'dev':
                    $result += 0;
                    break;
            }
        } else {
            $result += 50;
            // for final
        }
        return $result;
    }

Usage Example

コード例 #1
0
 /**
  * Test version to int conversion.
  *
  * @param string $version Version string
  * @param int    $numeric Integer matching version
  *
  * @return void
  *
  * @dataProvider dataVersions
  */
 public function testVersionToInt($version, $numeric)
 {
     $versionInformation = new VersionInformation();
     $this->assertEquals($numeric, $versionInformation->versionToInt($version));
 }
All Usage Examples Of PMA\libraries\VersionInformation::versionToInt