|
@@ -13,27 +13,41 @@
|
|
namespace Composer\Package\LinkConstraint;
|
|
namespace Composer\Package\LinkConstraint;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Defines a conjunctive set of constraints on the target of a package link
|
|
|
|
|
|
+ * Defines a conjunctive or disjunctive set of constraints on the target of a package link
|
|
*
|
|
*
|
|
* @author Nils Adermann <naderman@naderman.de>
|
|
* @author Nils Adermann <naderman@naderman.de>
|
|
|
|
+ * @author Jordi Boggiano <j.boggiano@seld.be>
|
|
*/
|
|
*/
|
|
class MultiConstraint implements LinkConstraintInterface
|
|
class MultiConstraint implements LinkConstraintInterface
|
|
{
|
|
{
|
|
protected $constraints;
|
|
protected $constraints;
|
|
protected $prettyString;
|
|
protected $prettyString;
|
|
|
|
+ protected $conjunctive;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Sets operator and version to compare a package with
|
|
* Sets operator and version to compare a package with
|
|
*
|
|
*
|
|
- * @param array $constraints A conjunctive set of constraints
|
|
|
|
|
|
+ * @param array $constraints A set of constraints
|
|
|
|
+ * @param bool $conjunctive Whether the constraints should be treated as conjunctive or disjunctive
|
|
*/
|
|
*/
|
|
- public function __construct(array $constraints)
|
|
|
|
|
|
+ public function __construct(array $constraints, $conjunctive = true)
|
|
{
|
|
{
|
|
$this->constraints = $constraints;
|
|
$this->constraints = $constraints;
|
|
|
|
+ $this->conjunctive = $conjunctive;
|
|
}
|
|
}
|
|
|
|
|
|
public function matches(LinkConstraintInterface $provider)
|
|
public function matches(LinkConstraintInterface $provider)
|
|
{
|
|
{
|
|
|
|
+ if (false === $this->conjunctive) {
|
|
|
|
+ foreach ($this->constraints as $constraint) {
|
|
|
|
+ if ($constraint->matches($provider)) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
foreach ($this->constraints as $constraint) {
|
|
foreach ($this->constraints as $constraint) {
|
|
if (!$constraint->matches($provider)) {
|
|
if (!$constraint->matches($provider)) {
|
|
return false;
|
|
return false;
|
|
@@ -64,6 +78,6 @@ class MultiConstraint implements LinkConstraintInterface
|
|
$constraints[] = $constraint->__toString();
|
|
$constraints[] = $constraint->__toString();
|
|
}
|
|
}
|
|
|
|
|
|
- return '['.implode(', ', $constraints).']';
|
|
|
|
|
|
+ return '['.implode($this->conjunctive ? ', ' : ' | ', $constraints).']';
|
|
}
|
|
}
|
|
}
|
|
}
|