PHP code example of fractal / semver

1. Go to this page and download the library: Download fractal/semver library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fractal / semver example snippets



    
use Fractal\SemVer\SemanticVersion;
    
## Create instance of SemVer
## If SemVer not valid, throws \Fractal\SemVer\Exceptions\ParseVersionException
$version = SemanticVersion::fromString('1.0.0'); # \Fractal\SemVer\Contracts\VersionInterface
$other = SemanticVersion::fromString('0.1.0'); # \Fractal\SemVer\Contracts\VersionInterface

## Version can compare each other
## If compare operator not valid, throws \Fractal\SemVer\Exceptions\InvalidOperatorException
## If version and other version are not instance of each other, throws \Fractal\SemVer\Exceptions\VersionClassNotEqualException
$version->eq($other); # false
$version->gte($other); # true


    
use Fractal\SemVer\SemanticVersion;
use Fractal\SemVer\Comparator;
    
## Create instance of SemVer
## If SemVer not valid, throws \Fractal\SemVer\Exceptions\ParseVersionException
$version = SemanticVersion::fromString('1.0.0'); # \Fractal\SemVer\Contracts\VersionInterface
$other = SemanticVersion::fromString('0.1.0'); # \Fractal\SemVer\Contracts\VersionInterface

## Compare versions with comparator
## If compare operator not valid, throws \Fractal\SemVer\Exceptions\InvalidOperatorException
## If version and other version are not instance of each other, throws \Fractal\SemVer\Exceptions\VersionClassNotEqualException
Comparator::eq($version, $other); # false
Comparator::gte($version, $other); # true