The Herrera\Version\Comparator class will compare any two instances of
Herrera\Version\Version, which also includes Herrera\Version\Builder.
To perform a simple comparison, you may call the compareTo() method:
use Herrera\Version\Comparator;
use Herrera\Version\Version;
$left = new Version(1, 0, 0);
$right = new Version(1, 0, 0);
$result = Comparator::compareTo($left, $right); // returns "0" (zero)You may use any of the following class constants to check the result:
Comparator::EQUAL_TO(0, zero)Comparator::GREATER_THAN(1, one)Comparator::LESS_THAN(-1, negative one)
To check if two versions are equal, you may call the isEqualTo() method:
$result = Comparator::isEqualTo($left, $right); // returns "true"To check if one version is greater than another, you may call the
isGreaterThan() method. The method will check of the first version ($left)
is greater than the second ($right):
$left = new Version(2, 0, 0);
$right = new Version(1, 0, 0);
$result = Comparator::isGreaterThan($left, $right); // returns "true"To check if one version is less than another, you may call the isGreaterThan()
method. The method will check of the first version ($left) is less than the
second ($right):
$left = new Version(1, 0, 0);
$right = new Version(2, 0, 0);
$result = Comparator::isLessThan($left, $right); // returns "true"