Download the PHP package sanmai/version-info without Composer
On this page you can find all versions of the php package sanmai/version-info. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package version-info
Version info parser
This small library solves a problem where a package wants to know or report own version.
This is not a new problem, e.g. there's ocramius/package-versions, but it depends heavely on Composer, and not without an associated IO penalty.
On the contrary, this package solves the same problem but without any extra IO whatsoever. What you need is to instruct Git to expand placeholders (detailed instructions below) when adding a file with a constant to an archive of a tagged release. Then you feed this constant to the library, and there is your version.
Sure, you can't be certain people always install a package from archives. In this case you can use
either abovementioned ocramius/package-versions, or
use two auxillary classes this library provides to fetch version strings right from Git or from a branch
alias from composer.json
.
Installation
This library needs PHP 7.4 or greater. It was tested to work under PHP 7.x and 8.0.
Usage
Create a PHP class (or use existing class) with the following constant:
Amend .gitattributes
with a path to the file with the class with export-subst
attribute:
Where you want to know your version, call a version reader:
That's all!
Testing
To verify that your version constant is being correctly replaced you can use git archive
command, pointing it at a tag, or a branch:
The constant should contain something like:
Fallback readers
Apart from PlaceholderVersionReader
there are GitVersionReader
and ComposerBranchAliasVersionReader
. See this example for details.
Memoization
Any of these classes do not do their own memoization. If you need memoization and lazy loading, try Later, a deferred object manager.
License
This project is licensed under the terms of the MIT license.
All versions of version-info with dependencies
ext-json Version *