Legoktm has uploaded a new change for review.
https://gerrit.wikimedia.org/r/243023
Change subject: Upgrade composer/semver to 1.0.0
......................................................................
Upgrade composer/semver to 1.0.0
Change-Id: Icf73630e60fe7d586d7ed249abc1d3014b67cbe6
---
M composer.json
M composer.lock
M composer/autoload_classmap.php
M composer/installed.json
M composer/semver/CHANGELOG.md
M composer/semver/README.md
M composer/semver/src/Comparator.php
R composer/semver/src/Constraint/AbstractConstraint.php
R composer/semver/src/Constraint/Constraint.php
A composer/semver/src/Constraint/ConstraintInterface.php
M composer/semver/src/Constraint/EmptyConstraint.php
D composer/semver/src/Constraint/LinkConstraintInterface.php
M composer/semver/src/Constraint/MultiConstraint.php
A composer/semver/src/Semver.php
M composer/semver/src/VersionParser.php
15 files changed, 407 insertions(+), 237 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/vendor
refs/changes/23/243023/1
diff --git a/composer.json b/composer.json
index 0b5c891..9c23185 100644
--- a/composer.json
+++ b/composer.json
@@ -9,7 +9,7 @@
},
"prefer-stable": true,
"require": {
- "composer/semver": "0.1.0",
+ "composer/semver": "1.0.0",
"cssjanus/cssjanus": "1.1.1",
"firebase/php-jwt": "2.1.0",
"kzykhys/pygments": "1.0",
diff --git a/composer.lock b/composer.lock
index 7d4f965..19de444 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,21 +4,21 @@
"Read more about it at
https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
- "hash": "6551ecfafd6fb8f4672316012253be56",
- "content-hash": "6f7d40f95a0ba1e9b234c0edb2f31bd3",
+ "hash": "1eaf03424ca729fd2b63c3b411639fcc",
+ "content-hash": "deb2694786785b13129a4a9e34aff00f",
"packages": [
{
"name": "composer/semver",
- "version": "0.1.0",
+ "version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/composer/semver.git",
- "reference": "f6469477aa1952f2fcbd0ab52fcc7662f1dd0173"
+ "reference": "d0e1ccc6d44ab318b758d709e19176037da6b1ba"
},
"dist": {
"type": "zip",
- "url":
"https://api.github.com/repos/composer/semver/zipball/f6469477aa1952f2fcbd0ab52fcc7662f1dd0173",
- "reference": "f6469477aa1952f2fcbd0ab52fcc7662f1dd0173",
+ "url":
"https://api.github.com/repos/composer/semver/zipball/d0e1ccc6d44ab318b758d709e19176037da6b1ba",
+ "reference": "d0e1ccc6d44ab318b758d709e19176037da6b1ba",
"shasum": ""
},
"require": {
@@ -66,7 +66,7 @@
"validation",
"versioning"
],
- "time": "2015-07-23 06:21:50"
+ "time": "2015-09-21 09:42:36"
},
{
"name": "cssjanus/cssjanus",
diff --git a/composer/autoload_classmap.php b/composer/autoload_classmap.php
index ad743ab..7ebc517 100644
--- a/composer/autoload_classmap.php
+++ b/composer/autoload_classmap.php
@@ -60,11 +60,12 @@
'Cdb\\Writer\\DBA' => $vendorDir . '/wikimedia/cdb/src/Writer/DBA.php',
'Cdb\\Writer\\PHP' => $vendorDir . '/wikimedia/cdb/src/Writer/PHP.php',
'Composer\\Semver\\Comparator' => $vendorDir .
'/composer/semver/src/Comparator.php',
+ 'Composer\\Semver\\Constraint\\AbstractConstraint' => $vendorDir .
'/composer/semver/src/Constraint/AbstractConstraint.php',
+ 'Composer\\Semver\\Constraint\\Constraint' => $vendorDir .
'/composer/semver/src/Constraint/Constraint.php',
+ 'Composer\\Semver\\Constraint\\ConstraintInterface' => $vendorDir .
'/composer/semver/src/Constraint/ConstraintInterface.php',
'Composer\\Semver\\Constraint\\EmptyConstraint' => $vendorDir .
'/composer/semver/src/Constraint/EmptyConstraint.php',
- 'Composer\\Semver\\Constraint\\LinkConstraintInterface' => $vendorDir .
'/composer/semver/src/Constraint/LinkConstraintInterface.php',
'Composer\\Semver\\Constraint\\MultiConstraint' => $vendorDir .
'/composer/semver/src/Constraint/MultiConstraint.php',
- 'Composer\\Semver\\Constraint\\SpecificConstraint' => $vendorDir .
'/composer/semver/src/Constraint/SpecificConstraint.php',
- 'Composer\\Semver\\Constraint\\VersionConstraint' => $vendorDir .
'/composer/semver/src/Constraint/VersionConstraint.php',
+ 'Composer\\Semver\\Semver' => $vendorDir .
'/composer/semver/src/Semver.php',
'Composer\\Semver\\VersionParser' => $vendorDir .
'/composer/semver/src/VersionParser.php',
'Elastica\\AbstractUpdateAction' => $vendorDir .
'/ruflin/elastica/lib/Elastica/AbstractUpdateAction.php',
'Elastica\\Aggregation\\AbstractAggregation' => $vendorDir .
'/ruflin/elastica/lib/Elastica/Aggregation/AbstractAggregation.php',
diff --git a/composer/installed.json b/composer/installed.json
index 7a92ffb..f883b09 100644
--- a/composer/installed.json
+++ b/composer/installed.json
@@ -384,69 +384,6 @@
]
},
{
- "name": "composer/semver",
- "version": "0.1.0",
- "version_normalized": "0.1.0.0",
- "source": {
- "type": "git",
- "url": "https://github.com/composer/semver.git",
- "reference": "f6469477aa1952f2fcbd0ab52fcc7662f1dd0173"
- },
- "dist": {
- "type": "zip",
- "url":
"https://api.github.com/repos/composer/semver/zipball/f6469477aa1952f2fcbd0ab52fcc7662f1dd0173",
- "reference": "f6469477aa1952f2fcbd0ab52fcc7662f1dd0173",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.2"
- },
- "require-dev": {
- "phpunit/phpunit": "~4.5",
- "phpunit/phpunit-mock-objects": "~2.3"
- },
- "time": "2015-07-23 06:21:50",
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "0.1-dev"
- }
- },
- "installation-source": "dist",
- "autoload": {
- "psr-4": {
- "Composer\\Semver\\": "src"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Rob Bast",
- "email": "[email protected]"
- },
- {
- "name": "Nils Adermann",
- "email": "[email protected]",
- "homepage": "http://www.naderman.de"
- },
- {
- "name": "Jordi Boggiano",
- "email": "[email protected]",
- "homepage": "http://seld.be"
- }
- ],
- "description": "Semver library that offers utilities, version
constraint parsing and validation.",
- "keywords": [
- "semantic",
- "semver",
- "validation",
- "versioning"
- ]
- },
- {
"name": "wikimedia/wrappedstring",
"version": "v2.0.0",
"version_normalized": "2.0.0.0",
@@ -1139,5 +1076,68 @@
],
"description": "Compute a relative filepath between two paths.",
"homepage": "https://www.mediawiki.org/wiki/RelPath"
+ },
+ {
+ "name": "composer/semver",
+ "version": "1.0.0",
+ "version_normalized": "1.0.0.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/composer/semver.git",
+ "reference": "d0e1ccc6d44ab318b758d709e19176037da6b1ba"
+ },
+ "dist": {
+ "type": "zip",
+ "url":
"https://api.github.com/repos/composer/semver/zipball/d0e1ccc6d44ab318b758d709e19176037da6b1ba",
+ "reference": "d0e1ccc6d44ab318b758d709e19176037da6b1ba",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.2"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4.5",
+ "phpunit/phpunit-mock-objects": "~2.3"
+ },
+ "time": "2015-09-21 09:42:36",
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "0.1-dev"
+ }
+ },
+ "installation-source": "dist",
+ "autoload": {
+ "psr-4": {
+ "Composer\\Semver\\": "src"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Rob Bast",
+ "email": "[email protected]"
+ },
+ {
+ "name": "Nils Adermann",
+ "email": "[email protected]",
+ "homepage": "http://www.naderman.de"
+ },
+ {
+ "name": "Jordi Boggiano",
+ "email": "[email protected]",
+ "homepage": "http://seld.be"
+ }
+ ],
+ "description": "Semver library that offers utilities, version
constraint parsing and validation.",
+ "keywords": [
+ "semantic",
+ "semver",
+ "validation",
+ "versioning"
+ ]
}
]
diff --git a/composer/semver/CHANGELOG.md b/composer/semver/CHANGELOG.md
index 37d29de..8352cb7 100644
--- a/composer/semver/CHANGELOG.md
+++ b/composer/semver/CHANGELOG.md
@@ -3,6 +3,18 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
+### [1.0.0] 2015-09-21
+
+ * Break: `VersionConstraint` renamed to `Constraint`.
+ * Break: `SpecificConstraint` renamed to `AbstractConstraint`.
+ * Break: `LinkConstraintInterface` renamed to `ConstraintInterface`.
+ * Break: `VersionParser::parseNameVersionPairs` was removed.
+ * Changed: `VersionParser::parseConstraints` allows (but ignores) build
metadata now.
+ * Changed: `VersionParser::parseConstraints` allows (but ignores) prefixing
numeric versions with a 'v' now.
+ * Changed: Fixed namespace(s) of test files.
+ * Changed: `Comparator::compare` no longer throws `InvalidArgumentException`.
+ * Changed: `VersionConstraint` now throws `InvalidArgumentException`.
+
### [0.1.0] 2015-07-23
* Added: `Composer\Semver\Comparator`, various methods to compare versions.
diff --git a/composer/semver/README.md b/composer/semver/README.md
index c0b34ce..c8b6979 100644
--- a/composer/semver/README.md
+++ b/composer/semver/README.md
@@ -8,6 +8,7 @@
[](https://travis-ci.org/composer/semver)
+
Installation
------------
@@ -17,23 +18,33 @@
$ composer require composer/semver
```
+
Requirements
------------
* PHP 5.3.2 is required but using the latest version of PHP is highly
recommended.
+
+Version Comparison
+------------------
+
+For details on how versions are compared, refer to the
[Versions](https://getcomposer.org/doc/articles/versions.md)
+article in the documentation section of the
[getcomposer.org](https://getcomposer.org) website.
+
+
Basic usage
-----------
-The `Composer\Semver\Comparator` class provides the following high-level
-functions for comparing versions:
+### Comparator
-* greaterThan
-* greaterThanOrEqualTo
-* lessThan
-* lessThanOrEqualTo
-* equalTo
-* notEqualTo
+The `Composer\Semver\Comparator` class provides the following methods for
comparing versions:
+
+* greaterThan($v1, $v2)
+* greaterThanOrEqualTo($v1, $v2)
+* lessThan($v1, $v2)
+* lessThanOrEqualTo($v1, $v2)
+* equalTo($v1, $v2)
+* notEqualTo($v1, $v2)
Each function takes two version strings as arguments. For example:
@@ -43,6 +54,15 @@
Comparator::greaterThan('1.25.0', '1.24.0'); // 1.25.0 > 1.24.0
```
+### Semver
+
+The `Composer\Semver\Semver` class providers the following methods:
+
+* satisfies($version, $constraints)
+* satisfiedBy($constraint, array $versions)
+* sort($versions)
+* rsort($versions)
+
License
-------
diff --git a/composer/semver/src/Comparator.php
b/composer/semver/src/Comparator.php
index 8afce22..a9d758f 100644
--- a/composer/semver/src/Comparator.php
+++ b/composer/semver/src/Comparator.php
@@ -11,12 +11,12 @@
namespace Composer\Semver;
-use Composer\Semver\Constraint\VersionConstraint;
+use Composer\Semver\Constraint\Constraint;
class Comparator
{
/**
- * Whether $version1 > $version2.
+ * Evaluates the expression: $version1 > $version2.
*
* @param string $version1
* @param string $version2
@@ -29,7 +29,7 @@
}
/**
- * Whether $version1 >= $version2.
+ * Evaluates the expression: $version1 >= $version2.
*
* @param string $version1
* @param string $version2
@@ -42,7 +42,7 @@
}
/**
- * Whether $version1 < $version2.
+ * Evaluates the expression: $version1 < $version2.
*
* @param string $version1
* @param string $version2
@@ -55,7 +55,7 @@
}
/**
- * Whether $version1 <= $version2.
+ * Evaluates the expression: $version1 <= $version2.
*
* @param string $version1
* @param string $version2
@@ -68,7 +68,7 @@
}
/**
- * Whether $version1 == $version2.
+ * Evaluates the expression: $version1 == $version2.
*
* @param string $version1
* @param string $version2
@@ -81,7 +81,7 @@
}
/**
- * Whether $version1 != $version2.
+ * Evaluates the expression: $version1 != $version2.
*
* @param string $version1
* @param string $version2
@@ -94,28 +94,18 @@
}
/**
- * Evaluate $version1 $operator $version2.
+ * Evaluates the expression: $version1 $operator $version2.
*
* @param string $version1
- * @param string $operator Comparison operator like ">" or "<=", etc.
+ * @param string $operator
* @param string $version2
- *
- * @throws \InvalidArgumentException
*
* @return bool
*/
public static function compare($version1, $operator, $version2)
{
- if (!in_array($operator, VersionConstraint::getSupportedOperators())) {
- throw new \InvalidArgumentException(sprintf(
- 'Operator "%s" not supported, expected one of: %s',
- $operator,
- implode(', ', VersionConstraint::getSupportedOperators())
- ));
- }
+ $constraint = new Constraint($operator, $version2);
- $constraint = new VersionConstraint($operator, $version2);
-
- return $constraint->matches(new VersionConstraint('==', $version1));
+ return $constraint->matches(new Constraint('==', $version1));
}
}
diff --git a/composer/semver/src/Constraint/SpecificConstraint.php
b/composer/semver/src/Constraint/AbstractConstraint.php
similarity index 79%
rename from composer/semver/src/Constraint/SpecificConstraint.php
rename to composer/semver/src/Constraint/AbstractConstraint.php
index 334dd1f..ccd834f 100644
--- a/composer/semver/src/Constraint/SpecificConstraint.php
+++ b/composer/semver/src/Constraint/AbstractConstraint.php
@@ -12,26 +12,26 @@
namespace Composer\Semver\Constraint;
/**
- * Provides a common basis for specific package link constraints.
- *
- * @author Nils Adermann <[email protected]>
+ * Base constraint class.
*/
-abstract class SpecificConstraint implements LinkConstraintInterface
+abstract class AbstractConstraint implements ConstraintInterface
{
/** @var string */
protected $prettyString;
/**
- * @param LinkConstraintInterface $provider
+ * @param ConstraintInterface $provider
*
* @return bool
*/
- public function matches(LinkConstraintInterface $provider)
+ public function matches(ConstraintInterface $provider)
{
if ($provider instanceof MultiConstraint) {
// turn matching around to find a match
return $provider->matches($this);
- } elseif ($provider instanceof $this) {
+ }
+
+ if ($provider instanceof $this) {
// see note at bottom of this class declaration
return $this->matchSpecific($provider);
}
diff --git a/composer/semver/src/Constraint/VersionConstraint.php
b/composer/semver/src/Constraint/Constraint.php
similarity index 74%
rename from composer/semver/src/Constraint/VersionConstraint.php
rename to composer/semver/src/Constraint/Constraint.php
index 94f5b5e..8bc68db 100644
--- a/composer/semver/src/Constraint/VersionConstraint.php
+++ b/composer/semver/src/Constraint/Constraint.php
@@ -12,14 +12,11 @@
namespace Composer\Semver\Constraint;
/**
- * Constrains a package link based on package version.
- *
- * Version numbers must be compatible with version_compare
- *
- * @author Nils Adermann <[email protected]>
+ * Defines a constraint.
*/
-class VersionConstraint extends SpecificConstraint
+class Constraint extends AbstractConstraint
{
+ /* operator integer values */
const OP_EQ = 0;
const OP_LT = 1;
const OP_LE = 2;
@@ -27,6 +24,11 @@
const OP_GE = 4;
const OP_NE = 5;
+ /**
+ * Operator to integer translation table.
+ *
+ * @var array
+ */
private static $transOpStr = array(
'=' => self::OP_EQ,
'==' => self::OP_EQ,
@@ -38,6 +40,11 @@
'!=' => self::OP_NE,
);
+ /**
+ * Integer to operator translation table.
+ *
+ * @var array
+ */
private static $transOpInt = array(
self::OP_EQ => '==',
self::OP_LT => '<',
@@ -47,7 +54,10 @@
self::OP_NE => '!=',
);
+ /** @var string */
private $operator;
+
+ /** @var string */
private $version;
/**
@@ -61,13 +71,23 @@
}
/**
- * Sets operator and version to compare a package with.
+ * Sets operator and version to compare with.
*
- * @param string $operator A comparison operator
- * @param string $version A version to compare to
+ * @param string $operator
+ * @param string $version
+ *
+ * @throws \InvalidArgumentException if invalid operator is given.
*/
public function __construct($operator, $version)
{
+ if (!isset(self::$transOpStr[$operator])) {
+ throw new \InvalidArgumentException(sprintf(
+ 'Invalid operator "%s" given, expected one of: %s',
+ $operator,
+ implode(', ', self::getSupportedOperators())
+ ));
+ }
+
$this->operator = self::$transOpStr[$operator];
$this->version = $version;
}
@@ -76,14 +96,25 @@
* @param string $a
* @param string $b
* @param string $operator
- * @param bool|false $compareBranches
+ * @param bool $compareBranches
*
- * @return bool|mixed
+ * @throws \InvalidArgumentException if invalid operator is given.
+ *
+ * @return bool
*/
public function versionCompare($a, $b, $operator, $compareBranches = false)
{
+ if (!isset(self::$transOpStr[$operator])) {
+ throw new \InvalidArgumentException(sprintf(
+ 'Invalid operator "%s" given, expected one of: %s',
+ $operator,
+ implode(', ', self::getSupportedOperators())
+ ));
+ }
+
$aIsBranch = 'dev-' === substr($a, 0, 4);
$bIsBranch = 'dev-' === substr($b, 0, 4);
+
if ($aIsBranch && $bIsBranch) {
return $operator === '==' && $a === $b;
}
@@ -97,12 +128,12 @@
}
/**
- * @param VersionConstraint $provider
+ * @param Constraint $provider
* @param bool $compareBranches
*
* @return bool
*/
- public function matchSpecific(VersionConstraint $provider,
$compareBranches = false)
+ public function matchSpecific(Constraint $provider, $compareBranches =
false)
{
$noEqualOp = str_replace('=', '', self::$transOpInt[$this->operator]);
$providerNoEqualOp = str_replace('=', '',
self::$transOpInt[$provider->operator]);
diff --git a/composer/semver/src/Constraint/ConstraintInterface.php
b/composer/semver/src/Constraint/ConstraintInterface.php
new file mode 100644
index 0000000..78c099c
--- /dev/null
+++ b/composer/semver/src/Constraint/ConstraintInterface.php
@@ -0,0 +1,37 @@
+<?php
+
+/*
+ * This file is part of composer/semver.
+ *
+ * (c) Composer <https://github.com/composer>
+ *
+ * For the full copyright and license information, please view
+ * the LICENSE file that was distributed with this source code.
+ */
+
+namespace Composer\Semver\Constraint;
+
+interface ConstraintInterface
+{
+ /**
+ * @param ConstraintInterface $provider
+ *
+ * @return bool
+ */
+ public function matches(ConstraintInterface $provider);
+
+ /**
+ * @param string $prettyString
+ */
+ public function setPrettyString($prettyString);
+
+ /**
+ * @return string
+ */
+ public function getPrettyString();
+
+ /**
+ * @return string
+ */
+ public function __toString();
+}
diff --git a/composer/semver/src/Constraint/EmptyConstraint.php
b/composer/semver/src/Constraint/EmptyConstraint.php
index f906030..faba56b 100644
--- a/composer/semver/src/Constraint/EmptyConstraint.php
+++ b/composer/semver/src/Constraint/EmptyConstraint.php
@@ -12,21 +12,19 @@
namespace Composer\Semver\Constraint;
/**
- * Defines an absence of constraints.
- *
- * @author Jordi Boggiano <[email protected]>
+ * Defines the absence of a constraint.
*/
-class EmptyConstraint implements LinkConstraintInterface
+class EmptyConstraint implements ConstraintInterface
{
/** @var string */
protected $prettyString;
/**
- * @param LinkConstraintInterface $provider
+ * @param ConstraintInterface $provider
*
* @return bool
*/
- public function matches(LinkConstraintInterface $provider)
+ public function matches(ConstraintInterface $provider)
{
return true;
}
diff --git a/composer/semver/src/Constraint/LinkConstraintInterface.php
b/composer/semver/src/Constraint/LinkConstraintInterface.php
deleted file mode 100644
index 21f3421..0000000
--- a/composer/semver/src/Constraint/LinkConstraintInterface.php
+++ /dev/null
@@ -1,28 +0,0 @@
-<?php
-
-/*
- * This file is part of composer/semver.
- *
- * (c) Composer <https://github.com/composer>
- *
- * For the full copyright and license information, please view
- * the LICENSE file that was distributed with this source code.
- */
-
-namespace Composer\Semver\Constraint;
-
-/**
- * Defines a constraint on a link between two packages.
- *
- * @author Nils Adermann <[email protected]>
- */
-interface LinkConstraintInterface
-{
- public function matches(LinkConstraintInterface $provider);
-
- public function setPrettyString($prettyString);
-
- public function getPrettyString();
-
- public function __toString();
-}
diff --git a/composer/semver/src/Constraint/MultiConstraint.php
b/composer/semver/src/Constraint/MultiConstraint.php
index a688439..0d769b7 100644
--- a/composer/semver/src/Constraint/MultiConstraint.php
+++ b/composer/semver/src/Constraint/MultiConstraint.php
@@ -12,14 +12,11 @@
namespace Composer\Semver\Constraint;
/**
- * Defines a conjunctive or disjunctive set of constraints on the target of a
package link.
- *
- * @author Nils Adermann <[email protected]>
- * @author Jordi Boggiano <[email protected]>
+ * Defines a conjunctive or disjunctive set of constraints.
*/
-class MultiConstraint implements LinkConstraintInterface
+class MultiConstraint implements ConstraintInterface
{
- /** @var array */
+ /** @var ConstraintInterface[] */
protected $constraints;
/** @var string */
@@ -29,9 +26,7 @@
protected $conjunctive;
/**
- * Sets operator and version to compare a package with.
- *
- * @param array $constraints A set of constraints
+ * @param ConstraintInterface[] $constraints A set of constraints
* @param bool $conjunctive Whether the constraints should be treated as
conjunctive or disjunctive
*/
public function __construct(array $constraints, $conjunctive = true)
@@ -41,11 +36,11 @@
}
/**
- * @param LinkConstraintInterface $provider
+ * @param ConstraintInterface $provider
*
* @return bool
*/
- public function matches(LinkConstraintInterface $provider)
+ public function matches(ConstraintInterface $provider)
{
if (false === $this->conjunctive) {
foreach ($this->constraints as $constraint) {
@@ -93,7 +88,7 @@
{
$constraints = array();
foreach ($this->constraints as $constraint) {
- $constraints[] = $constraint->__toString();
+ $constraints[] = (string) $constraint;
}
return '[' . implode($this->conjunctive ? ' ' : ' || ', $constraints)
. ']';
diff --git a/composer/semver/src/Semver.php b/composer/semver/src/Semver.php
new file mode 100644
index 0000000..0225bb5
--- /dev/null
+++ b/composer/semver/src/Semver.php
@@ -0,0 +1,127 @@
+<?php
+
+/*
+ * This file is part of composer/semver.
+ *
+ * (c) Composer <https://github.com/composer>
+ *
+ * For the full copyright and license information, please view
+ * the LICENSE file that was distributed with this source code.
+ */
+
+namespace Composer\Semver;
+
+use Composer\Semver\Constraint\Constraint;
+
+class Semver
+{
+ const SORT_ASC = 1;
+ const SORT_DESC = -1;
+
+ /** @var VersionParser */
+ private static $versionParser;
+
+ /**
+ * Determine if given version satisfies given constraints.
+ *
+ * @param string $version
+ * @param string $constraints
+ *
+ * @return bool
+ */
+ public static function satisfies($version, $constraints)
+ {
+ if (null === self::$versionParser) {
+ self::$versionParser = new VersionParser();
+ }
+
+ $versionParser = self::$versionParser;
+ $provider = new Constraint('==', $versionParser->normalize($version));
+ $constraints = $versionParser->parseConstraints($constraints);
+
+ return $constraints->matches($provider);
+ }
+
+ /**
+ * Return all versions that satisfy given constraints.
+ *
+ * @param array $versions
+ * @param string $constraints
+ *
+ * @return array
+ */
+ public static function satisfiedBy(array $versions, $constraints)
+ {
+ $versions = array_filter($versions, function ($version) use
($constraints) {
+ return Semver::satisfies($version, $constraints);
+ });
+
+ return array_values($versions);
+ }
+
+ /**
+ * Sort given array of versions.
+ *
+ * @param array $versions
+ *
+ * @return array
+ */
+ public static function sort(array $versions)
+ {
+ return self::usort($versions, self::SORT_ASC);
+ }
+
+ /**
+ * Sort given array of versions in reverse.
+ *
+ * @param array $versions
+ *
+ * @return array
+ */
+ public static function rsort(array $versions)
+ {
+ return self::usort($versions, self::SORT_DESC);
+ }
+
+ /**
+ * @param array $versions
+ * @param int $direction
+ *
+ * @return array
+ */
+ private static function usort(array $versions, $direction)
+ {
+ if (null === self::$versionParser) {
+ self::$versionParser = new VersionParser();
+ }
+
+ $versionParser = self::$versionParser;
+ $normalized = array();
+
+ // Normalize outside of usort() scope for minor performance increase.
+ // Creates an array of arrays: [[normalized, key], ...]
+ foreach ($versions as $key => $version) {
+ $normalized[] = array($versionParser->normalize($version), $key);
+ }
+
+ usort($normalized, function (array $left, array $right) use
($direction) {
+ if ($left[0] === $right[0]) {
+ return 0;
+ }
+
+ if (Comparator::lessThan($left[0], $right[0])) {
+ return -$direction;
+ }
+
+ return $direction;
+ });
+
+ // Recreate input array, using the original indexes which are now in
sorted order.
+ $sorted = array();
+ foreach ($normalized as $item) {
+ $sorted[] = $versions[$item[1]];
+ }
+
+ return $sorted;
+ }
+}
diff --git a/composer/semver/src/VersionParser.php
b/composer/semver/src/VersionParser.php
index f70d2c3..269aee9 100644
--- a/composer/semver/src/VersionParser.php
+++ b/composer/semver/src/VersionParser.php
@@ -11,10 +11,10 @@
namespace Composer\Semver;
+use Composer\Semver\Constraint\ConstraintInterface;
use Composer\Semver\Constraint\EmptyConstraint;
-use Composer\Semver\Constraint\LinkConstraintInterface;
use Composer\Semver\Constraint\MultiConstraint;
-use Composer\Semver\Constraint\VersionConstraint;
+use Composer\Semver\Constraint\Constraint;
/**
* Version parser.
@@ -95,12 +95,12 @@
$fullVersion = $version;
}
- // ignore aliases and just assume the alias is required instead of the
source
+ // strip off aliasing
if (preg_match('{^([^,\s]+) +as +([^,\s]+)$}', $version, $match)) {
$version = $match[1];
}
- // ignore build metadata
+ // strip off build metadata
if (preg_match('{^([^,\s+]+)\+[^\s]+$}', $version, $match)) {
$version = $match[1];
}
@@ -115,21 +115,16 @@
}
// match classical versioning
- if (preg_match('{^v?(\d{1,3})(\.\d+)?(\.\d+)?(\.\d+)?' .
self::$modifierRegex . '$}i', $version, $matches)) {
+ if (preg_match('{^v?(\d{1,5})(\.\d+)?(\.\d+)?(\.\d+)?' .
self::$modifierRegex . '$}i', $version, $matches)) {
$version = $matches[1]
. (!empty($matches[2]) ? $matches[2] : '.0')
. (!empty($matches[3]) ? $matches[3] : '.0')
. (!empty($matches[4]) ? $matches[4] : '.0');
$index = 5;
- } elseif
(preg_match('{^v?(\d{4}(?:[.:-]?\d{2}){1,6}(?:[.:-]?\d{1,3})?)' .
self::$modifierRegex . '$}i', $version, $matches)) { // match date-based
versioning
+ // match date(time) based versioning
+ } elseif
(preg_match('{^v?(\d{4}(?:[.:-]?\d{2}){1,6}(?:[.:-]?\d{1,3})?)' .
self::$modifierRegex . '$}i', $version, $matches)) {
$version = preg_replace('{\D}', '-', $matches[1]);
$index = 2;
- } elseif (preg_match('{^v?(\d{4,})(\.\d+)?(\.\d+)?(\.\d+)?' .
self::$modifierRegex . '$}i', $version, $matches)) {
- $version = $matches[1]
- . (!empty($matches[2]) ? $matches[2] : '.0')
- . (!empty($matches[3]) ? $matches[3] : '.0')
- . (!empty($matches[4]) ? $matches[4] : '.0');
- $index = 5;
}
// add version modifiers if a version was matched
@@ -175,7 +170,7 @@
*/
public function parseNumericAliasPrefix($branch)
{
- if (preg_match('/^(?P<version>(\d+\\.)*\d+)(?:\.x)?-dev$/i', $branch,
$matches)) {
+ if (preg_match('{^(?P<version>(\d+\\.)*\d+)(?:\.x)?-dev$}i', $branch,
$matches)) {
return $matches['version'] . '.';
}
@@ -197,7 +192,7 @@
return $this->normalize($name);
}
- if
(preg_match('#^v?(\d+)(\.(?:\d+|[xX*]))?(\.(?:\d+|[xX*]))?(\.(?:\d+|[xX*]))?$#i',
$name, $matches)) {
+ if
(preg_match('{^v?(\d+)(\.(?:\d+|[xX*]))?(\.(?:\d+|[xX*]))?(\.(?:\d+|[xX*]))?$}i',
$name, $matches)) {
$version = '';
for ($i = 1; $i < 5; ++$i) {
$version .= isset($matches[$i]) ? str_replace(array('*', 'X'),
'x', $matches[$i]) : '.x';
@@ -214,7 +209,7 @@
*
* @param string $constraints
*
- * @return LinkConstraintInterface
+ * @return ConstraintInterface
*/
public function parseConstraints($constraints)
{
@@ -266,6 +261,8 @@
/**
* @param string $constraint
*
+ * @throws \UnexpectedValueException
+ *
* @return array
*/
private function parseConstraint($constraint)
@@ -281,13 +278,13 @@
return array(new EmptyConstraint());
}
- $versionRegex = '(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?' .
self::$modifierRegex;
+ $versionRegex = 'v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?' .
self::$modifierRegex . '(?:\+[^\s]+)?';
- // match tilde constraints
- // like wildcard constraints, unsuffixed tilde constraints say that
they must be greater than the previous
- // version, to ensure that unstable instances of the current version
are allowed.
- // however, if a stability suffix is added to the constraint, then a
>= match on the current version is
- // used instead
+ // Tilde Range
+ //
+ // Like wildcard constraints, unsuffixed tilde constraints say that
they must be greater than the previous
+ // version, to ensure that unstable instances of the current version
are allowed. However, if a stability
+ // suffix is added to the constraint, then a >= match on the current
version is used instead.
if (preg_match('{^~>?' . $versionRegex . '$}i', $constraint,
$matches)) {
if (substr($constraint, 0, 2) === '~>') {
throw new \UnexpectedValueException(
@@ -320,14 +317,15 @@
if (!$stabilitySuffix) {
$stabilitySuffix = '-dev';
}
+
$lowVersion = $this->manipulateVersionString($matches, $position,
0) . $stabilitySuffix;
- $lowerBound = new VersionConstraint('>=', $lowVersion);
+ $lowerBound = new Constraint('>=', $lowVersion);
// For upper bound, we increment the position of one more
significance,
// but highPosition = 0 would be illegal
$highPosition = max(1, $position - 1);
$highVersion = $this->manipulateVersionString($matches,
$highPosition, 1) . '-dev';
- $upperBound = new VersionConstraint('<', $highVersion);
+ $upperBound = new Constraint('<', $highVersion);
return array(
$lowerBound,
@@ -335,7 +333,11 @@
);
}
- // match caret constraints
+ // Caret Range
+ //
+ // Allows changes that do not modify the left-most non-zero digit in
the [major, minor, patch] tuple.
+ // In other words, this allows patch and minor updates for versions
1.0.0 and above, patch updates for
+ // versions 0.X >=0.1.0, and no updates for versions 0.0.X
if (preg_match('{^\^' . $versionRegex . '($)}i', $constraint,
$matches)) {
// Work out which position in the version we are operating at
if ('0' !== $matches[1] || '' === $matches[2]) {
@@ -353,12 +355,12 @@
}
$lowVersion = $this->normalize(substr($constraint .
$stabilitySuffix, 1));
- $lowerBound = new VersionConstraint('>=', $lowVersion);
+ $lowerBound = new Constraint('>=', $lowVersion);
// For upper bound, we increment the position of one more
significance,
// but highPosition = 0 would be illegal
$highVersion = $this->manipulateVersionString($matches, $position,
1) . '-dev';
- $upperBound = new VersionConstraint('<', $highVersion);
+ $upperBound = new Constraint('<', $highVersion);
return array(
$lowerBound,
@@ -366,8 +368,11 @@
);
}
- // match wildcard constraints
- if (preg_match('{^(\d+)(?:\.(\d+))?(?:\.(\d+))?\.[xX*]$}',
$constraint, $matches)) {
+ // X Range
+ //
+ // Any of X, x, or * may be used to "stand in" for one of the numeric
values in the [major, minor, patch] tuple.
+ // A partial version range is treated as an X-Range, so the special
character is in fact optional.
+ if (preg_match('{^(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.[xX*])+$}',
$constraint, $matches)) {
if (isset($matches[3]) && '' !== $matches[3]) {
$position = 3;
} elseif (isset($matches[2]) && '' !== $matches[2]) {
@@ -380,16 +385,21 @@
$highVersion = $this->manipulateVersionString($matches, $position,
1) . '-dev';
if ($lowVersion === '0.0.0.0-dev') {
- return array(new VersionConstraint('<', $highVersion));
+ return array(new Constraint('<', $highVersion));
}
return array(
- new VersionConstraint('>=', $lowVersion),
- new VersionConstraint('<', $highVersion),
+ new Constraint('>=', $lowVersion),
+ new Constraint('<', $highVersion),
);
}
- // match hyphen constraints
+ // Hyphen Range
+ //
+ // Specifies an inclusive set. If a partial version is provided as the
first version in the inclusive range,
+ // then the missing pieces are replaced with zeroes. If a partial
version is provided as the second version in
+ // the inclusive range, then all versions that start with the supplied
parts of the tuple are accepted, but
+ // nothing that would be greater than the provided tuple parts.
if (preg_match('{^(?P<from>' . $versionRegex . ') +- +(?P<to>' .
$versionRegex . ')($)}i', $constraint, $matches)) {
// Calculate the stability suffix
$lowStabilitySuffix = '';
@@ -398,7 +408,7 @@
}
$lowVersion = $this->normalize($matches['from']);
- $lowerBound = new VersionConstraint('>=', $lowVersion .
$lowStabilitySuffix);
+ $lowerBound = new Constraint('>=', $lowVersion .
$lowStabilitySuffix);
$empty = function ($x) {
return ($x === 0 || $x === '0') ? false : empty($x);
@@ -406,11 +416,11 @@
if ((!$empty($matches[11]) && !$empty($matches[12])) ||
!empty($matches[14]) || !empty($matches[16])) {
$highVersion = $this->normalize($matches['to']);
- $upperBound = new VersionConstraint('<=', $highVersion);
+ $upperBound = new Constraint('<=', $highVersion);
} else {
$highMatch = array('', $matches[10], $matches[11],
$matches[12], $matches[13]);
$highVersion = $this->manipulateVersionString($highMatch,
$empty($matches[11]) ? 1 : 2, 1) . '-dev';
- $upperBound = new VersionConstraint('<', $highVersion);
+ $upperBound = new Constraint('<', $highVersion);
}
return array(
@@ -419,7 +429,7 @@
);
}
- // match operators constraints
+ // Basic Comparators
if (preg_match('{^(<>|!=|>=?|<=?|==?)?\s*(.*)}', $constraint,
$matches)) {
try {
$version = $this->normalize($matches[2]);
@@ -434,7 +444,7 @@
}
}
- return array(new VersionConstraint($matches[1] ?: '=',
$version));
+ return array(new Constraint($matches[1] ?: '=', $version));
} catch (\Exception $e) {
}
}
@@ -453,7 +463,7 @@
* Support function for {@link parseConstraint()}
*
* @param array $matches Array with version parts in array indexes 1,2,3,4
- * @param int $position 1,2,3,4 - which segment of the version to decrement
+ * @param int $position 1,2,3,4 - which segment of the version to
increment/decrement
* @param int $increment
* @param string $pad The string to pad version parts after $position
*
@@ -482,6 +492,13 @@
return $matches[1] . '.' . $matches[2] . '.' . $matches[3] . '.' .
$matches[4];
}
+ /**
+ * Expand shorthand stability string to long version.
+ *
+ * @param string $stability
+ *
+ * @return string
+ */
private function expandStability($stability)
{
$stability = strtolower($stability);
@@ -499,35 +516,5 @@
default:
return $stability;
}
- }
-
- /**
- * Parses a name/version pairs and returns an array of pairs.
- *
- * @param array $pairs a set of package/version pairs separated by ":",
"=" or " "
- *
- * @return array[] array of arrays containing a name and (if provided) a
version
- */
- public function parseNameVersionPairs(array $pairs)
- {
- $pairs = array_values($pairs);
- $result = array();
-
- for ($i = 0, $count = count($pairs); $i < $count; ++$i) {
- $pair = preg_replace('{^([^=: ]+)[=: ](.*)$}', '$1 $2',
trim($pairs[$i]));
- if (false === strpos($pair, ' ') && isset($pairs[$i + 1]) && false
=== strpos($pairs[$i + 1], '/')) {
- $pair .= ' ' . $pairs[$i + 1];
- ++$i;
- }
-
- if (strpos($pair, ' ')) {
- list($name, $version) = explode(' ', $pair, 2);
- $result[] = array('name' => $name, 'version' => $version);
- } else {
- $result[] = array('name' => $pair);
- }
- }
-
- return $result;
}
}
--
To view, visit https://gerrit.wikimedia.org/r/243023
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Icf73630e60fe7d586d7ed249abc1d3014b67cbe6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/vendor
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits