Minimum PHP Version Latest Stable Version Build Status codecov

Composer Package Version

Helper class to get a current version from composer.json file in your project

If you want to get only string version, you can use mazanax/composer-project-version

Installation

composer require mazanax/composer-version-semver

Usage

• Accessing Major/Minor/Patch version

<?php

$packageVersion = \MZNX\ComposerPackageSemver\PackageVersionSemver::init(__DIR__ . '/path/to/composer.json');
$version = $packageVersion->getVersion();

echo $version->getMajor() . PHP_EOL;
echo $version->getMinor() . PHP_EOL;
echo $version->getPatch() . PHP_EOL;

• Getting version as string

<?php

$packageVersion = \MZNX\ComposerPackageSemver\PackageVersionSemver::init(__DIR__ . '/path/to/composer.json');
$version = $packageVersion->getVersionAsString();

echo $version . PHP_EOL;

License

MIT