Chris@0
|
1 # Version
|
Chris@0
|
2
|
Chris@0
|
3 **Version** is a library that helps with managing the version number of Git-hosted PHP projects.
|
Chris@0
|
4
|
Chris@0
|
5 ## Installation
|
Chris@0
|
6
|
Chris@0
|
7 Simply add a dependency on `sebastian/version` to your project's `composer.json` file if you use [Composer](http://getcomposer.org/) to manage the dependencies of your project.
|
Chris@0
|
8
|
Chris@0
|
9 ## Usage
|
Chris@0
|
10
|
Chris@0
|
11 The constructor of the `SebastianBergmann\Version` class expects two parameters:
|
Chris@0
|
12
|
Chris@0
|
13 * `$release` is the version number of the latest release (`X.Y.Z`, for instance) or the name of the release series (`X.Y`) when no release has been made from that branch / for that release series yet.
|
Chris@0
|
14 * `$path` is the path to the directory (or a subdirectory thereof) where the sourcecode of the project can be found. Simply passing `__DIR__` here usually suffices.
|
Chris@0
|
15
|
Chris@0
|
16 Apart from the constructor, the `SebastianBergmann\Version` class has a single public method: `getVersion()`.
|
Chris@0
|
17
|
Chris@0
|
18 Here is a contrived example that shows the basic usage:
|
Chris@0
|
19
|
Chris@0
|
20 <?php
|
Chris@0
|
21 $version = new SebastianBergmann\Version(
|
Chris@0
|
22 '3.7.10', '/usr/local/src/phpunit'
|
Chris@0
|
23 );
|
Chris@0
|
24
|
Chris@0
|
25 var_dump($version->getVersion());
|
Chris@0
|
26 ?>
|
Chris@0
|
27
|
Chris@0
|
28 string(18) "3.7.10-17-g00f3408"
|
Chris@0
|
29
|
Chris@0
|
30 When a new release is prepared, the string that is passed to the constructor as the first argument needs to be updated.
|
Chris@0
|
31
|
Chris@0
|
32 ### How SebastianBergmann\Version::getVersion() works
|
Chris@0
|
33
|
Chris@0
|
34 * If `$path` is not (part of) a Git repository and `$release` is in `X.Y.Z` format then `$release` is returned as-is.
|
Chris@0
|
35 * If `$path` is not (part of) a Git repository and `$release` is in `X.Y` format then `$release` is returned suffixed with `-dev`.
|
Chris@0
|
36 * If `$path` is (part of) a Git repository and `$release` is in `X.Y.Z` format then the output of `git describe --tags` is returned as-is.
|
Chris@0
|
37 * If `$path` is (part of) a Git repository and `$release` is in `X.Y` format then a string is returned that begins with `X.Y` and ends with information from `git describe --tags`.
|