# 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
<?php
use SonsOfPHP\Component\Version\Version;

// You can create versions two different ways
$version = new Version('1.2.3');
$version = Version::from('1.2.3');

echo $version; // prints "1.2.3"
$versionString = $version->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
<?php
use SonsOfPHP\Component\Version\Version;

// Create a new Version that includes Pre-release and/or Build Metadata
$version = new Version('1.2.3-RC1+buildMetaData');

// You can grab the info as well
$preRelease = $version->getPreRelease(); // $preRelease === "RC1"
$build = $version->getBuild(); // $build === "RC1"
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sonsofphp.com/components/version.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
