Rename RelationConstraints to Links in the Package namespace.
Constraints have been generalised to allow matching requiring and providing constraints against each other.main
parent
e03983697a
commit
8c9f8fb86f
@ -1,54 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Composer.
|
|
||||||
*
|
|
||||||
* (c) Nils Adermann <naderman@naderman.de>
|
|
||||||
* Jordi Boggiano <j.boggiano@seld.be>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Composer\DependencyResolver;
|
|
||||||
|
|
||||||
use Composer\DependencyResolver\RelationConstraint\RelationConstraintInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Nils Adermann <naderman@naderman.de>
|
|
||||||
*/
|
|
||||||
class PackageRelation
|
|
||||||
{
|
|
||||||
protected $fromPackageName;
|
|
||||||
protected $toPackageName;
|
|
||||||
protected $constraint;
|
|
||||||
protected $description;
|
|
||||||
|
|
||||||
public function __construct($fromPackageName, $toPackageName, RelationConstraintInterface $constraint, $description = 'relates to')
|
|
||||||
{
|
|
||||||
$this->fromPackageName = $fromPackageName;
|
|
||||||
$this->toPackageName = $toPackageName;
|
|
||||||
$this->constraint = $constraint;
|
|
||||||
$this->description = $description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getToPackageName()
|
|
||||||
{
|
|
||||||
return $this->toPackageName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getFromPackageName()
|
|
||||||
{
|
|
||||||
return $this->fromPackageName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getConstraint()
|
|
||||||
{
|
|
||||||
return $this->constraint;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function __toString()
|
|
||||||
{
|
|
||||||
return $this->fromPackageName.' '.$this->description.' '.$this->toPackageName.' ('.$this->constraint.')';
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Composer.
|
||||||
|
*
|
||||||
|
* (c) Nils Adermann <naderman@naderman.de>
|
||||||
|
* Jordi Boggiano <j.boggiano@seld.be>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Composer\Package;
|
||||||
|
|
||||||
|
use Composer\Package\LinkConstraint\LinkConstraintInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a link between two packages, represented by their names
|
||||||
|
*
|
||||||
|
* @author Nils Adermann <naderman@naderman.de>
|
||||||
|
*/
|
||||||
|
class Link
|
||||||
|
{
|
||||||
|
protected $source;
|
||||||
|
protected $target;
|
||||||
|
protected $constraint;
|
||||||
|
protected $description;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new package link.
|
||||||
|
*
|
||||||
|
* @param string $source
|
||||||
|
* @param string $target
|
||||||
|
* @param LinkConstraintInterface $constraint Constraint applying to the target of this link
|
||||||
|
* @param string $description Used to create a descriptive string representation
|
||||||
|
*/
|
||||||
|
public function __construct($source, $target, LinkConstraintInterface $constraint, $description = 'relates to')
|
||||||
|
{
|
||||||
|
$this->source = $source;
|
||||||
|
$this->target = $target;
|
||||||
|
$this->constraint = $constraint;
|
||||||
|
$this->description = $description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSource()
|
||||||
|
{
|
||||||
|
return $this->source;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTarget()
|
||||||
|
{
|
||||||
|
return $this->target;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getConstraint()
|
||||||
|
{
|
||||||
|
return $this->constraint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return $this->source.' '.$this->description.' '.$this->target.' ('.$this->constraint.')';
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Composer.
|
||||||
|
*
|
||||||
|
* (c) Nils Adermann <naderman@naderman.de>
|
||||||
|
* Jordi Boggiano <j.boggiano@seld.be>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Composer\Package\LinkConstraint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines a conjuctive set of constraints on the target of a package link
|
||||||
|
*
|
||||||
|
* @author Nils Adermann <naderman@naderman.de>
|
||||||
|
*/
|
||||||
|
class MultiConstraint implements LinkConstraintInterface
|
||||||
|
{
|
||||||
|
protected $constraints;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets operator and version to compare a package with
|
||||||
|
*
|
||||||
|
* @param array $constraints A conjuctive set of constraints
|
||||||
|
*/
|
||||||
|
public function __construct(array $constraints)
|
||||||
|
{
|
||||||
|
$this->constraints = $constraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function matches(LinkConstraintInterface $provider)
|
||||||
|
{
|
||||||
|
foreach ($this->constraints as $constraint) {
|
||||||
|
if (!$constraint->matches($provider)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return $this->operator.' '.$this->version;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Composer.
|
||||||
|
*
|
||||||
|
* (c) Nils Adermann <naderman@naderman.de>
|
||||||
|
* Jordi Boggiano <j.boggiano@seld.be>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Composer\Package\LinkConstraint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a common basis for specific package link constraints
|
||||||
|
*
|
||||||
|
* @author Nils Adermann <naderman@naderman.de>
|
||||||
|
*/
|
||||||
|
class SpecificConstraint implements LinkConstraintInterface
|
||||||
|
{
|
||||||
|
public function matches(LinkConstraintInterface $provider)
|
||||||
|
{
|
||||||
|
if ($provider instanceof MultiConstraint) {
|
||||||
|
// turn matching around to find a match
|
||||||
|
return $provider->matches($this);
|
||||||
|
} else if ($provider instanceof get_class($this)) {
|
||||||
|
return $this->matchSpecific($provider);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract public function matchSpecific($provider);
|
||||||
|
|
||||||
|
abstract public function __toString();
|
||||||
|
}
|
Loading…
Reference in New Issue