PHP code example of starburst / version

1. Go to this page and download the library: Download starburst/version library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

starburst / version example snippets


use Starburst\Version\Parser;

$parser = new Parser();

// Parse Semantic Versioning
$version = $parser->parseString('1.2.3-alpha.1+build.123');

// Parse Calendar Versioning
$calVer = $parser->parseString('2024.05.20');

// Parse from array
$versionFromArray = $parser->parseArray([
    'major' => 1,
    'minor' => 2,
    'patch' => 3,
]);

$v1 = $parser->parseString('1.2.3');
$v2 = $parser->parseString('1.2.4');

$v1->isLessThan($v2);         // true
$v1->isGreaterThan($v2);      // false
$v1->isEqualTo('1.2.3');      // true
$v1->compareTo($v2);          // -1

use Starburst\Version\Bump;

$version = $parser->parseString('1.2.3');
$nextVersion = $version->bump(Bump::Minor); // 1.3.0

// with pre-release and build metadata
$nextVersion = $version->bump(
	Bump::Path,
	preRelease: PreRelease::from('alpha', '1'),
	buildMetaData: BuildMetaData::from('f3b2974'),
); // Today's date (e.g., 1.2.4-alpha.1+f3b2974)

$version = $parser->parseString('2024.01.01');
$nextVersion = $version->bump(); // Today's date (e.g., 2026.07.13)

// or specify a specific date
$nextVersion = $version->bump(releaseData: new DateTimeImmutable('2024-01-01')); // 2024.01.01

// with pre-release and build metadata
$nextVersion = $version->bump(
	preRelease: PreRelease::from('alpha', '1'),
	buildMetaData: BuildMetaData::from('f3b2974'),
); // Today's date (e.g., 2026.07.13-alpha.1+f3b2974)