static public function compare($version1, $version2, $operator = null)
    {
        $version1 = trim($version1);
        $version2 = trim($version2);
        
        // Because version_compare consider 2.1 < 2.1.0...
        $version1 = self::appendPatchVersion($version1);
        $version2 = self::appendPatchVersion($version2);
        
        // Check if the versions are known...
        $knownVersions = self::knownVersions();
        if (self::isKnown($version1) === false) {
            $msg = "Version '${version1}' is not a known QTI version. Known versions are '" . implode(', ', $knownVersions) . "'.";
            throw new InvalidArgumentException($msg);
        } elseif (self::isKnown($version2) === false) {
            $msg = "Version '${version2}' is not a known QTI version. Known versions are '" . implode(', ', $knownVersions) . "'.";
            throw new InvalidArgumentException($msg);
        }
        
        // Check if operator is correct.
        $knownOperators = array('<', 'lt', '<=', 'le', '>', 'gt', '>=', 'ge', '==', '=', 'eq', '!=', '<>', 'ne');
        if (is_null($operator) === true || in_array($operator, $knownOperators) === true) {
            return (is_null($operator) === true) ? version_compare($version1, $version2) : version_compare($version1, $version2, $operator);
        } else {
            $msg = "Unknown operator '${operator}'. Known operators are '" . implode(', ', $knownOperators) . "'.";
            throw new InvalidArgumentException($msg);
        }
    }
static public function compare($version1, $version2, $operator = null)
    {
        $version1 = trim($version1);
        $version2 = trim($version2);
        
        // Because version_compare consider 2.1 < 2.1.0...
        $version1 = self::appendPatchVersion($version1);
        $version2 = self::appendPatchVersion($version2);
        
        // Check if the versions are known...
        $knownVersions = self::knownVersions();
        if (self::isKnown($version1) === false) {
            $msg = "Version '${version1}' is not a known QTI version. Known versions are '" . implode(', ', $knownVersions) . "'.";
            throw new InvalidArgumentException($msg);
        } elseif (self::isKnown($version2) === false) {
            $msg = "Version '${version2}' is not a known QTI version. Known versions are '" . implode(', ', $knownVersions) . "'.";
            throw new InvalidArgumentException($msg);
        }
        
        // Check if operator is correct.
        $knownOperators = array('<', 'lt', '<=', 'le', '>', 'gt', '>=', 'ge', '==', '=', 'eq', '!=', '<>', 'ne');
        if (is_null($operator) === true || in_array($operator, $knownOperators) === true) {
            return (is_null($operator) === true) ? version_compare($version1, $version2) : version_compare($version1, $version2, $operator);
        } else {
            $msg = "Unknown operator '${operator}'. Known operators are '" . implode(', ', $knownOperators) . "'.";
            throw new InvalidArgumentException($msg);
        }
    }
static public function compare ( $ version1 , $ version2 , $ operator = null ) { $ version1 = trim ( $ version1 ) ; $ version2 = trim ( $ version2 ) ; // Because version_compare consider 2.1 < 2.1.0... $ version1 = self :: appendPatchVersion ( $ version1 ) ; $ version2 = self :: appendPatchVersion ( $ version2 ) ; // Check if the versions are known... $ knownVersions = self :: knownVersions ( ) ; if ( self :: isKnown ( $ version1 ) === false ) { $ msg = "Version '${version1}' is not a known QTI version. Known versions are '" . implode ( ', ' , $ knownVersions ) . "'." ; throw new InvalidArgumentException ( $ msg ) ; } elseif ( self :: isKnown ( $ version2 ) === false ) { $ msg = "Version '${version2}' is not a known QTI version. Known versions are '" . implode ( ', ' , $ knownVersions ) . "'." ; throw new InvalidArgumentException ( $ msg ) ; } // Check if operator is correct. $ knownOperators = array ( '<' , 'lt' , '<=' , 'le' , '>' , 'gt' , '>=' , 'ge' , '==' , '=' , 'eq' , '!=' , '<>' , 'ne' ) ; if ( is_null ( $ operator ) === true || in_array ( $ operator , $ knownOperators ) === true ) { return ( is_null ( $ operator ) === true ) ? version_compare ( $ version1 , $ version2 ) : version_compare ( $ version1 , $ version2 , $ operator ) ; } else { $ msg = "Unknown operator '${operator}'. Known operators are '" . implode ( ', ' , $ knownOperators ) . "'." ; throw new InvalidArgumentException ( $ msg ) ; } }
Compare two version numbers of QTI, following the rules of Semantic Versioning.

This method provides QTI version comparison. Two versions are compared using an optional operator.
When no $operator is provided, this method returns

* -1 if $version1 is lower than $version2
* 0 if $version1 is equal to $version2
* 1 if $version1 is greater than $version2

In case of using a specific $operator, the method returns true or false depending on
the $operator and versions given. Accepted operators are '<', 'lt', '<=', 'le', '>', 'gt',
'>=', 'ge', '==', '=', 'eq', '!=' and 'ne'.

If an unknown QTI version is given for $version1 or $version2 arguments, or if $operator
is an unknown operator, an InvalidArgumentException is thrown.

Important note: This metod will consider version '2.1' and '2.1.0' equal.

@param string $version1 A version number.
@param string $version2 A version number
@param string $operator An operator.
@throws \InvalidArgumentException
@return mixed
@see http://semver.org Semantic Versioning
Compare two version numbers of QTI following the rules of Semantic Versioning .