sebastian/version Documentation

repository·main·Indexed 27 days ago

https://github.com/sebastianbergmann/version

A PHP library for managing and formatting version numbers for Git-hosted projects. It provides consistent version strings based on Git tags and release series via the SebastianBergmann\Version class and its asString() method.

Tokens
410
Snippets
2
Records
3
Agent score
42%

What's inside sebastian/version

  1. Install sebastian/version via Composer

    main

    You can install this library as a project dependency or a development-only dependency using Composer.

    To add it as a local, per-project dependency:

    composer require sebastian/version

    To add it as a development-time dependency (e.g., for running test suites):

    composer require --dev sebastian/version
    composer require sebastian/version
  2. Use the SebastianBergmann\Version class

    main

    The SebastianBergmann\Version class manages version numbers for Git-hosted PHP projects.

    To instantiate the class, provide two parameters to the constructor:

    1. $release: The version number of the latest release (e.g., X.Y.Z) or the name of the release series (e.g., X.Y).
    2. $path: The path to the directory where the project sourcecode is located (e.g., __DIR__).

    Use the asString() method to retrieve the formatted version string.

    <?php declare(strict_types=1);
    use SebastianBergmann\Version;
    
    $version = new Version('1.0.0', __DIR__);
    
    var_dump($version->asString());
  3. Understand how Version::asString() formats output

    main

    The output of asString() depends on whether the provided $path is part of a Git repository and the format of the $release string provided to the constructor:

    Git Repository?$release FormatResulting Output
    NoX.Y.ZReturns $release as-is
    NoX.YReturns $release suffixed with -dev
    YesX.Y.ZReturns the output of git describe --tags
    YesX.YReturns a string starting with X.Y and ending with information from git describe --tags