PHP code example of naneau / project-versioner

1. Go to this page and download the library: Download naneau/project-versioner 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/ */

    

naneau / project-versioner example snippets


use Naneau\ProjectVersioner\Versioner;
use Naneau\ProjectVersioner\Reader\Git\Commit\Exec as GitCommitReader;

// Create a versioner
$versioner = new Versioner(array(new GitCommitReader));

// Short commit hash like "gd8587c8"
$version = $versioner->get('/foo/bar');

use Naneau\ProjectVersioner\Versioner;
use Naneau\ProjectVersioner\Reader\Git\Tag\Exec as GitTagReader;

// Create a versioner
$versioner = new Versioner(array(new GitTagReader));

// Last tag
$version = $versioner->get('/foo/bar');

use Naneau\ProjectVersioner\Versioner;
use Naneau\ProjectVersioner\Reader\Git\Tag\Exec as GitTagReader;

// Create a versioner
$versioner = new Versioner(array(new GitTagReader));

// Last tag + commit info, like 4.3.2-9-gd504031
$version = $versioner->get('/foo/bar');

use Naneau\ProjectVersioner\Versioner;
use Naneau\ProjectVersioner\Reader\File as FileReader;

// Create a versioner
$versioner = new Versioner(array(
    // Reader for "VERSION" file
    new FileReader('VERSION')
));

// Retrieve version from versioner
$version = $versioner->get('/foo/bar');

use Naneau\ProjectVersioner\Versioner;
use Naneau\ProjectVersioner\Reader\Finder\MTime as MTimeReader;

// Create a versioner
$versioner = new Versioner(array(
    new MTimeReader('*.txt') // Look at all *.txt files
));

// Highest mtime, like 1410806782
$version = $versioner->get('/foo/bar');

use Naneau\ProjectVersioner\Versioner;
use Naneau\ProjectVersioner\Reader\Finder\Contents as ContentsReader;

$versioner = new Versioner(array(
    new ContentsReader('*.jpg')
));

// Short hash of file contents, like gd504031
$version = $versioner->get('/foo/bar');

use Naneau\ProjectVersioner\Versioner;
use Naneau\ProjectVersioner\Reader\Composer as ComposerReader;

$versioner = new Versioner(array(new ComposerReader));

// Short hash like "ae9b8a"
$version = $versioner->get('/foo/bar');

use Naneau\ProjectVersioner\Versioner;
use Naneau\ProjectVersioner\Reader\ComposerPackage as ComposerPackageReader;

$versioner = new Versioner(array(
    new ComposerPackageReader('symfony/filesystem')
));

// Composer Version (SemVer) like "v2.5.4"
$version = $versioner->get('/foo/bar');

use Naneau\ProjectVersioner\Versioner;
use Naneau\ProjectVersioner\Reader\ComposerPackage as ComposerPackageReader;
use Naneau\ProjectVersioner\Reader\Git\Tag\Exec as GitTagReader;

$versioner = new Versioner(array(
    new ComposerPackageReader('symfony/filesystem'),
    new GitTagReader
));

// First version found
$version = $versioner->get('/foo/bar');

// Composite of all readers, like "v0.3.4-gd504031"
$combinedVersion = $versioner->getCombined('/foo/bar');

// You can specify the separator
$combinedVersionUnderscore = $versioner->getCombined('/foo/bar', '_');