See More

> For the complete documentation index, see [llms.txt](https://docs.sonsofphp.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sonsofphp.com/components/version.md). # Version The Version component allows you an easy way to parse and compare versions. It supports both Semversion and package manager syntax. ## Installation ```shell composer require sonsofphp/version ``` ## Usage The base `Version` supports semver standards. ```php toString(); // $versionString === "1.2.3" // Easy API $major = $version->getMajor(); // $major === 1 $minor = $version->getMinor(); // $minor === 2 $patch = $version->getPatch(); // $patch === 3 // Comparing Versions is easy too $currentVersion = new Version('1.1.1'); $latestVersion = new Version('1.1.2'); // if $latestVersion > $currentVersion if ($latestVersion->isGreaterThan($currentVersion)) { // run upgrade } // Also supports "isLessThan" and "isEqualTo" ``` ### Advanced Usage You can also use Pre-release and Build Metadata with your versions. ```php getPreRelease(); // $preRelease === "RC1" $build = $version->getBuild(); // $build === "RC1" ```