public static function match($version, $constraints = null)
    {
        if (is_string($version) && empty($version)) {
            return false;
        }

        if (empty($constraints) || $version == $constraints) {
            return true;
        }

        $parser = new VersionParser();
        $modifierRegex = '[\-\@]dev(\#\w+)?';
        $constraints = preg_replace('{' . $modifierRegex . '$}i', '', $constraints);
        $version = $parser->normalize($version);
        $version = preg_replace('{' . $modifierRegex . '$}i', '', $version);

        if (empty($constraints) || $version == $constraints) {
            return true;
        }

        try {
            $pkgConstraint = new VersionConstraint('==', $version);
            $constraintObjects = $parser->parseConstraints($constraints);

            return $constraintObjects->matches($pkgConstraint);
        } catch (\Exception $ex) {
            return false;
        }
    }
public static function match($version, $constraints = null)
    {
        if (is_string($version) && empty($version)) {
            return false;
        }

        if (empty($constraints) || $version == $constraints) {
            return true;
        }

        $parser = new VersionParser();
        $modifierRegex = '[\-\@]dev(\#\w+)?';
        $constraints = preg_replace('{' . $modifierRegex . '$}i', '', $constraints);
        $version = $parser->normalize($version);
        $version = preg_replace('{' . $modifierRegex . '$}i', '', $version);

        if (empty($constraints) || $version == $constraints) {
            return true;
        }

        try {
            $pkgConstraint = new VersionConstraint('==', $version);
            $constraintObjects = $parser->parseConstraints($constraints);

            return $constraintObjects->matches($pkgConstraint);
        } catch (\Exception $ex) {
            return false;
        }
    }
public static function match ( $ version , $ constraints = null ) { if ( is_string ( $ version ) && empty ( $ version ) ) { return false ; } if ( empty ( $ constraints ) || $ version == $ constraints ) { return true ; } $ parser = new VersionParser ( ) ; $ modifierRegex = '[\-\@]dev(\#\w+)?' ; $ constraints = preg_replace ( '{' . $ modifierRegex . '$}i' , '' , $ constraints ) ; $ version = $ parser -> normalize ( $ version ) ; $ version = preg_replace ( '{' . $ modifierRegex . '$}i' , '' , $ version ) ; if ( empty ( $ constraints ) || $ version == $ constraints ) { return true ; } try { $ pkgConstraint = new VersionConstraint ( '==' , $ version ) ; $ constraintObjects = $ parser -> parseConstraints ( $ constraints ) ; return $ constraintObjects -> matches ( $ pkgConstraint ) ; } catch ( \ Exception $ ex ) { return false ; } }
Check whether a version matches the given constraint.

### Example:

```php
Constraint::match('1.2.6', '>=1.1'); // returns true
```

@param string $version The version to check against (e.g. v4.2.6)
@param string $constraints A string representing a dependency constraints,
for instance, `>7.0 || 1.2`
@return bool True if compatible, false otherwise
@see https://getcomposer.org/doc/01-basic-usage.md#package-versions
Check whether a version matches the given constraint .