summaryrefslogtreecommitdiff
path: root/vendor/composer/semver/src/Constraint
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/composer/semver/src/Constraint')
-rw-r--r--vendor/composer/semver/src/Constraint/AbstractConstraint.php65
-rw-r--r--vendor/composer/semver/src/Constraint/Constraint.php181
-rw-r--r--vendor/composer/semver/src/Constraint/ConstraintInterface.php37
-rw-r--r--vendor/composer/semver/src/Constraint/EmptyConstraint.php59
-rw-r--r--vendor/composer/semver/src/Constraint/MultiConstraint.php96
5 files changed, 438 insertions, 0 deletions
diff --git a/vendor/composer/semver/src/Constraint/AbstractConstraint.php b/vendor/composer/semver/src/Constraint/AbstractConstraint.php
new file mode 100644
index 00000000..ccd834f6
--- /dev/null
+++ b/vendor/composer/semver/src/Constraint/AbstractConstraint.php
@@ -0,0 +1,65 @@
+<?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;
+
+/**
+ * Base constraint class.
+ */
+abstract class AbstractConstraint implements ConstraintInterface
+{
+ /** @var string */
+ protected $prettyString;
+
+ /**
+ * @param ConstraintInterface $provider
+ *
+ * @return bool
+ */
+ public function matches(ConstraintInterface $provider)
+ {
+ if ($provider instanceof MultiConstraint) {
+ // turn matching around to find a match
+ return $provider->matches($this);
+ }
+
+ if ($provider instanceof $this) {
+ // see note at bottom of this class declaration
+ return $this->matchSpecific($provider);
+ }
+
+ return true;
+ }
+
+ /**
+ * @param string $prettyString
+ */
+ public function setPrettyString($prettyString)
+ {
+ $this->prettyString = $prettyString;
+ }
+
+ /**
+ * @return string
+ */
+ public function getPrettyString()
+ {
+ if ($this->prettyString) {
+ return $this->prettyString;
+ }
+
+ return $this->__toString();
+ }
+
+ // implementations must implement a method of this format:
+ // not declared abstract here because type hinting violates parameter coherence (TODO right word?)
+ // public function matchSpecific(<SpecificConstraintType> $provider);
+}
diff --git a/vendor/composer/semver/src/Constraint/Constraint.php b/vendor/composer/semver/src/Constraint/Constraint.php
new file mode 100644
index 00000000..8bc68db7
--- /dev/null
+++ b/vendor/composer/semver/src/Constraint/Constraint.php
@@ -0,0 +1,181 @@
+<?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.
+ */
+class Constraint extends AbstractConstraint
+{
+ /* operator integer values */
+ const OP_EQ = 0;
+ const OP_LT = 1;
+ const OP_LE = 2;
+ const OP_GT = 3;
+ 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,
+ '<' => self::OP_LT,
+ '<=' => self::OP_LE,
+ '>' => self::OP_GT,
+ '>=' => self::OP_GE,
+ '<>' => self::OP_NE,
+ '!=' => self::OP_NE,
+ );
+
+ /**
+ * Integer to operator translation table.
+ *
+ * @var array
+ */
+ private static $transOpInt = array(
+ self::OP_EQ => '==',
+ self::OP_LT => '<',
+ self::OP_LE => '<=',
+ self::OP_GT => '>',
+ self::OP_GE => '>=',
+ self::OP_NE => '!=',
+ );
+
+ /** @var string */
+ private $operator;
+
+ /** @var string */
+ private $version;
+
+ /**
+ * Get all supported comparison operators.
+ *
+ * @return array
+ */
+ public static function getSupportedOperators()
+ {
+ return array_keys(self::$transOpStr);
+ }
+
+ /**
+ * Sets operator and version to compare with.
+ *
+ * @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;
+ }
+
+ /**
+ * @param string $a
+ * @param string $b
+ * @param string $operator
+ * @param bool $compareBranches
+ *
+ * @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;
+ }
+
+ // when branches are not comparable, we make sure dev branches never match anything
+ if (!$compareBranches && ($aIsBranch || $bIsBranch)) {
+ return false;
+ }
+
+ return version_compare($a, $b, $operator);
+ }
+
+ /**
+ * @param Constraint $provider
+ * @param bool $compareBranches
+ *
+ * @return bool
+ */
+ public function matchSpecific(Constraint $provider, $compareBranches = false)
+ {
+ $noEqualOp = str_replace('=', '', self::$transOpInt[$this->operator]);
+ $providerNoEqualOp = str_replace('=', '', self::$transOpInt[$provider->operator]);
+
+ $isEqualOp = self::OP_EQ === $this->operator;
+ $isNonEqualOp = self::OP_NE === $this->operator;
+ $isProviderEqualOp = self::OP_EQ === $provider->operator;
+ $isProviderNonEqualOp = self::OP_NE === $provider->operator;
+
+ // '!=' operator is match when other operator is not '==' operator or version is not match
+ // these kinds of comparisons always have a solution
+ if ($isNonEqualOp || $isProviderNonEqualOp) {
+ return !$isEqualOp && !$isProviderEqualOp
+ || $this->versionCompare($provider->version, $this->version, '!=', $compareBranches);
+ }
+
+ // an example for the condition is <= 2.0 & < 1.0
+ // these kinds of comparisons always have a solution
+ if ($this->operator !== self::OP_EQ && $noEqualOp === $providerNoEqualOp) {
+ return true;
+ }
+
+ if ($this->versionCompare($provider->version, $this->version, self::$transOpInt[$this->operator], $compareBranches)) {
+ // special case, e.g. require >= 1.0 and provide < 1.0
+ // 1.0 >= 1.0 but 1.0 is outside of the provided interval
+ if ($provider->version === $this->version
+ && self::$transOpInt[$provider->operator] === $providerNoEqualOp
+ && self::$transOpInt[$this->operator] !== $noEqualOp) {
+ return false;
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * @return string
+ */
+ public function __toString()
+ {
+ return self::$transOpInt[$this->operator] . ' ' . $this->version;
+ }
+}
diff --git a/vendor/composer/semver/src/Constraint/ConstraintInterface.php b/vendor/composer/semver/src/Constraint/ConstraintInterface.php
new file mode 100644
index 00000000..78c099ce
--- /dev/null
+++ b/vendor/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/vendor/composer/semver/src/Constraint/EmptyConstraint.php b/vendor/composer/semver/src/Constraint/EmptyConstraint.php
new file mode 100644
index 00000000..faba56bf
--- /dev/null
+++ b/vendor/composer/semver/src/Constraint/EmptyConstraint.php
@@ -0,0 +1,59 @@
+<?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 the absence of a constraint.
+ */
+class EmptyConstraint implements ConstraintInterface
+{
+ /** @var string */
+ protected $prettyString;
+
+ /**
+ * @param ConstraintInterface $provider
+ *
+ * @return bool
+ */
+ public function matches(ConstraintInterface $provider)
+ {
+ return true;
+ }
+
+ /**
+ * @param $prettyString
+ */
+ public function setPrettyString($prettyString)
+ {
+ $this->prettyString = $prettyString;
+ }
+
+ /**
+ * @return string
+ */
+ public function getPrettyString()
+ {
+ if ($this->prettyString) {
+ return $this->prettyString;
+ }
+
+ return $this->__toString();
+ }
+
+ /**
+ * @return string
+ */
+ public function __toString()
+ {
+ return '[]';
+ }
+}
diff --git a/vendor/composer/semver/src/Constraint/MultiConstraint.php b/vendor/composer/semver/src/Constraint/MultiConstraint.php
new file mode 100644
index 00000000..0d769b7c
--- /dev/null
+++ b/vendor/composer/semver/src/Constraint/MultiConstraint.php
@@ -0,0 +1,96 @@
+<?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 conjunctive or disjunctive set of constraints.
+ */
+class MultiConstraint implements ConstraintInterface
+{
+ /** @var ConstraintInterface[] */
+ protected $constraints;
+
+ /** @var string */
+ protected $prettyString;
+
+ /** @var bool */
+ protected $conjunctive;
+
+ /**
+ * @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)
+ {
+ $this->constraints = $constraints;
+ $this->conjunctive = $conjunctive;
+ }
+
+ /**
+ * @param ConstraintInterface $provider
+ *
+ * @return bool
+ */
+ public function matches(ConstraintInterface $provider)
+ {
+ if (false === $this->conjunctive) {
+ foreach ($this->constraints as $constraint) {
+ if ($constraint->matches($provider)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ foreach ($this->constraints as $constraint) {
+ if (!$constraint->matches($provider)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * @param string $prettyString
+ */
+ public function setPrettyString($prettyString)
+ {
+ $this->prettyString = $prettyString;
+ }
+
+ /**
+ * @return string
+ */
+ public function getPrettyString()
+ {
+ if ($this->prettyString) {
+ return $this->prettyString;
+ }
+
+ return $this->__toString();
+ }
+
+ /**
+ * @return string
+ */
+ public function __toString()
+ {
+ $constraints = array();
+ foreach ($this->constraints as $constraint) {
+ $constraints[] = (string) $constraint;
+ }
+
+ return '[' . implode($this->conjunctive ? ' ' : ' || ', $constraints) . ']';
+ }
+}