corneltek/versionkit

Versioning library

dev-master / 1.0.x-dev 2015-12-12 10:48 UTC

This package is auto-updated.

Last update: 2024-11-29 04:41:22 UTC


README

Build Status

Utility functions for manipulating version strings.

$versionStrs = [
    'php-5.3.1',
    'php-5.3.22',
    'php-5.4',
    'php-5',
    'hhvm-3.2',
    'php-5.3.0-dev',
    'php-5.3.0-alpha3',
    'php-5.3.0-beta2',
    'php-5.3.0-RC5',
    '5.3.0-dev',
    '5.3.0-alpha3',
    '5.3.0-beta2',
    '5.3.0-RC5',
    '5.3.3',
    '5.3.0',
    '5.3',
    '5',
];
foreach ($versionStrs as $versionStr) {
    $version = new Version($versionStr);
    $version->major;
    $version->minor;
    $version->patch;
    $version->getVersionNumber(); // 5.3.2
    $version->getCanonicalizedVersionName(); // php-5.3.0-dev
    $version->compare(new Version('php-5.3.2'));
}

VersionCollection

$versions = new VersionCollection(['php-5.4.0', 'php-5.5.0', 'php-7.0.0', 'php-5.3.0', 'php-5.3.3']);

$this->assertTrue( $versions->sortAscending() );
$this->assertEquals('["php-5.3.0","php-5.3.3","php-5.4.0","php-5.5.0","php-7.0.0"]', $versions->toJson());

$this->assertTrue( $versions->sortDescending() );
$this->assertEquals('["php-7.0.0","php-5.5.0","php-5.4.0","php-5.3.3","php-5.3.0"]', $versions->toJson());

$versions = new VersionCollection(['php-5.3.0', 'php-5.3.3', 'php-5.4.0', 'php-5.5.0', 'php-7.0.0']);
$versions7 = $versions->filterByMajorVersion(7);
$versions5 = $versions->filterByMajorVersion(5);