mirror of
https://github.com/composer/composer
synced 2025-05-10 00:53:06 +00:00
Import initial partial port of the libzypp satsolver.
This commit is contained in:
parent
ea13ad7669
commit
933cc6179b
23 changed files with 3149 additions and 0 deletions
62
src/Composer/DependencyResolver/ArrayRepository.php
Normal file
62
src/Composer/DependencyResolver/ArrayRepository.php
Normal file
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Composer\DependencyResolver;
|
||||
|
||||
/**
|
||||
* A repository implementation that simply stores packages in an array
|
||||
*
|
||||
* @author Nils Adermann <naderman@naderman.de>
|
||||
*/
|
||||
class ArrayRepository implements RepositoryInterface
|
||||
{
|
||||
protected $packages = array();
|
||||
|
||||
/**
|
||||
* Adds a new package to the repository
|
||||
*
|
||||
* @param Package $package
|
||||
*/
|
||||
public function addPackage(Package $package)
|
||||
{
|
||||
$this->packages[$package->getId()] = $package;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all contained packages
|
||||
*
|
||||
* @return array All packages
|
||||
*/
|
||||
public function getPackages()
|
||||
{
|
||||
return $this->packages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a package is contained in this repository
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function contains(Package $package)
|
||||
{
|
||||
return isset($this->packages[$package->getId()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of packages in this repository
|
||||
*
|
||||
* @return int Number of packages
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->packages);
|
||||
}
|
||||
}
|
63
src/Composer/DependencyResolver/DefaultPolicy.php
Normal file
63
src/Composer/DependencyResolver/DefaultPolicy.php
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Composer\DependencyResolver;
|
||||
|
||||
/**
|
||||
* @author Nils Adermann <naderman@naderman.de>
|
||||
*/
|
||||
class DefaultPolicy implements PolicyInterface
|
||||
{
|
||||
public function allowUninstall()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function allowDowngrade()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function versionCompare(Package $a, Package $b, $operator)
|
||||
{
|
||||
return version_compare($a->getVersion(), $b->getVersion(), $operator);
|
||||
}
|
||||
|
||||
public function findUpdatePackages(Solver $solver, Pool $pool, RepositoryInterface $repo, Package $package, $allowAll = false)
|
||||
{
|
||||
$packages = array();
|
||||
|
||||
foreach ($pool->whatProvides($package->getName()) as $candidate) {
|
||||
// skip old packages unless downgrades are an option
|
||||
if (!$allowAll && !$this->allowDowngrade() && $this->versionCompare($package, $candidate, '>')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($candidate != $package) {
|
||||
$packages[] = $candidate;
|
||||
}
|
||||
}
|
||||
|
||||
return $packages;
|
||||
}
|
||||
|
||||
public function installable(Solver $solver, Pool $pool, RepositoryInterface $repo, Package $package)
|
||||
{
|
||||
// todo: package blacklist?
|
||||
return true;
|
||||
}
|
||||
|
||||
public function selectPreferedPackages(array $literals)
|
||||
{
|
||||
// todo: prefer installed, recommended, highest priority repository, ...
|
||||
return array($literals[0]);
|
||||
}
|
||||
}
|
61
src/Composer/DependencyResolver/Literal.php
Normal file
61
src/Composer/DependencyResolver/Literal.php
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Composer\DependencyResolver;
|
||||
|
||||
/**
|
||||
* @author Nils Adermann <naderman@naderman.de>
|
||||
*/
|
||||
class Literal
|
||||
{
|
||||
protected $wanted;
|
||||
|
||||
public function __construct(Package $package, $wanted)
|
||||
{
|
||||
$this->package = $package;
|
||||
$this->wanted = $wanted;
|
||||
}
|
||||
|
||||
public function isWanted()
|
||||
{
|
||||
return $this->wanted;
|
||||
}
|
||||
|
||||
public function getPackage()
|
||||
{
|
||||
return $this->package;
|
||||
}
|
||||
|
||||
public function getPackageId()
|
||||
{
|
||||
return $this->package->getId();
|
||||
}
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return (($this->wanted) ? 1 : -1) * $this->package->getId();
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return ($this->isWanted() ? '+' : '-').$this->getPackage();
|
||||
}
|
||||
|
||||
public function inverted()
|
||||
{
|
||||
return new Literal($this->getPackage(), !$this->isWanted());
|
||||
}
|
||||
|
||||
public function equals(Literal $b)
|
||||
{
|
||||
return $this->getId() === $b->getId();
|
||||
}
|
||||
}
|
190
src/Composer/DependencyResolver/MemoryPackage.php
Normal file
190
src/Composer/DependencyResolver/MemoryPackage.php
Normal file
|
@ -0,0 +1,190 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Composer\DependencyResolver;
|
||||
|
||||
/**
|
||||
* A package with setters for all members to create it dynamically in memory
|
||||
*
|
||||
* @author Nils Adermann <naderman@naderman.de>
|
||||
*/
|
||||
class MemoryPackage extends Package
|
||||
{
|
||||
protected $releaseType;
|
||||
protected $version;
|
||||
|
||||
protected $requires = array();
|
||||
protected $conflicts = array();
|
||||
protected $provides = array();
|
||||
protected $replaces = array();
|
||||
protected $recommends = array();
|
||||
protected $suggests = array();
|
||||
|
||||
/**
|
||||
* Creates a new in memory package.
|
||||
*
|
||||
* @param string $name The package's name
|
||||
* @param string $version The package's version
|
||||
* @param string $releaseType The package's release type (beta/rc/stable)
|
||||
* @param int $id A positive unique id, zero to auto generate
|
||||
*/
|
||||
public function __construct($name, $version, $releaseType = 'stable', $id = 0)
|
||||
{
|
||||
parent::__construct($name, $id);
|
||||
|
||||
$this->releaseType = $releaseType;
|
||||
$this->version = $version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the release type
|
||||
*
|
||||
* @param string $releaseType
|
||||
*/
|
||||
public function setReleaseType($releaseType)
|
||||
{
|
||||
$this->releaseType = $releaseType;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getReleaseType()
|
||||
{
|
||||
return $this->releaseType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the version
|
||||
*
|
||||
* @param string $version
|
||||
*/
|
||||
public function setVersion($version)
|
||||
{
|
||||
$this->version = $version;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getVersion()
|
||||
{
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the required packages
|
||||
*
|
||||
* @param array $requires A set of package relations
|
||||
*/
|
||||
public function setRequires(array $requires)
|
||||
{
|
||||
$this->requires = $requires;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getRequires()
|
||||
{
|
||||
return $this->requires;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the conflicting packages
|
||||
*
|
||||
* @param array $conflicts A set of package relations
|
||||
*/
|
||||
public function setConflicts(array $conflicts)
|
||||
{
|
||||
$this->conflicts = $conflicts;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getConflicts()
|
||||
{
|
||||
return $this->conflicts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the provided virtual packages
|
||||
*
|
||||
* @param array $conflicts A set of package relations
|
||||
*/
|
||||
public function setProvides(array $provides)
|
||||
{
|
||||
$this->provides = $provides;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getProvides()
|
||||
{
|
||||
return $this->provides;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the packages this one replaces
|
||||
*
|
||||
* @param array $conflicts A set of package relations
|
||||
*/
|
||||
public function setReplaces(array $replaces)
|
||||
{
|
||||
$this->replaces = $replaces;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getReplaces()
|
||||
{
|
||||
return $this->replaces;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the recommended packages
|
||||
*
|
||||
* @param array $conflicts A set of package relations
|
||||
*/
|
||||
public function setRecommends(array $recommends)
|
||||
{
|
||||
$this->recommends = $recommends;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getRecommends()
|
||||
{
|
||||
return $this->recommends;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the suggested packages
|
||||
*
|
||||
* @param array $conflicts A set of package relations
|
||||
*/
|
||||
public function setSuggests(array $suggests)
|
||||
{
|
||||
$this->suggests = $suggests;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getSuggests()
|
||||
{
|
||||
return $this->suggests;
|
||||
}
|
||||
}
|
189
src/Composer/DependencyResolver/Package.php
Normal file
189
src/Composer/DependencyResolver/Package.php
Normal file
|
@ -0,0 +1,189 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
*
|
||||
* 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>
|
||||
*/
|
||||
abstract class Package
|
||||
{
|
||||
protected $name;
|
||||
protected $id;
|
||||
|
||||
static public $incremental_id = 1;
|
||||
|
||||
/**
|
||||
* All descendents' constructors should call this parent constructor
|
||||
*
|
||||
* @param string $name The package's name
|
||||
* @param int $id A positive unique id, zero to auto generate
|
||||
*/
|
||||
public function __construct($name, $id = 0)
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
if (!$id) {
|
||||
$this->id = self::$incremental_id++;
|
||||
} else {
|
||||
$this->id = $id;
|
||||
self::$incremental_id = $id + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the package's identifier
|
||||
*
|
||||
* @return int Package id - a unique positive number
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the package's name without version info, thus not a unique identifier
|
||||
*
|
||||
* @return string package name
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a set of names that could refer to this package
|
||||
*
|
||||
* No version or release type information should be included in any of the
|
||||
* names. Provided or replaced package names need to be returned as well.
|
||||
*
|
||||
* @return array An array of strings refering to this package
|
||||
*/
|
||||
public function getNames()
|
||||
{
|
||||
$names = array(
|
||||
$this->getName(),
|
||||
);
|
||||
|
||||
foreach ($this->getProvides() as $relation) {
|
||||
$names[] = $relation->getToPackageName();
|
||||
}
|
||||
|
||||
foreach ($this->getReplaces() as $relation) {
|
||||
$names[] = $relation->getToPackageName();
|
||||
}
|
||||
|
||||
return $names;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the package matches the given constraint directly or through
|
||||
* provided or replaced packages
|
||||
*
|
||||
* @param string $name Name of the package to be matched
|
||||
* @param RelationConstraintInterface $constraint The constraint to verify
|
||||
* @return bool Whether this package matches the name and constraint
|
||||
*/
|
||||
public function matches($name, RelationConstraintInterface $constraint)
|
||||
{
|
||||
if ($this->name === $name) {
|
||||
return $constraint->matches($this->getReleaseType(), $this->getVersion());
|
||||
}
|
||||
|
||||
foreach ($this->getProvides() as $relation) {
|
||||
if ($relation->getToPackageName() === $name) {
|
||||
return $constraint->matches($relation->getToReleaseType(), $relation->getToVersion());
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->getReplaces() as $relation) {
|
||||
if ($relation->getToPackageName() === $name) {
|
||||
return $constraint->matches($relation->getToReleaseType(), $relation->getToVersion());
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the release type of this package, e.g. stable or beta
|
||||
*
|
||||
* @return string The release type
|
||||
*/
|
||||
abstract public function getReleaseType();
|
||||
|
||||
/**
|
||||
* Returns the version of this package
|
||||
*
|
||||
* @return string version
|
||||
*/
|
||||
abstract public function getVersion();
|
||||
|
||||
/**
|
||||
* Returns a set of relations to packages which need to be installed before
|
||||
* this package can be installed
|
||||
*
|
||||
* @return array An array of package relations defining required packages
|
||||
*/
|
||||
abstract public function getRequires();
|
||||
|
||||
/**
|
||||
* Returns a set of relations to packages which must not be installed at the
|
||||
* same time as this package
|
||||
*
|
||||
* @return array An array of package relations defining conflicting packages
|
||||
*/
|
||||
abstract public function getConflicts();
|
||||
|
||||
/**
|
||||
* Returns a set of relations to virtual packages that are provided through
|
||||
* this package
|
||||
*
|
||||
* @return array An array of package relations defining provided packages
|
||||
*/
|
||||
abstract public function getProvides();
|
||||
|
||||
/**
|
||||
* Returns a set of relations to packages which can alternatively be
|
||||
* satisfied by installing this package
|
||||
*
|
||||
* @return array An array of package relations defining replaced packages
|
||||
*/
|
||||
abstract public function getReplaces();
|
||||
|
||||
/**
|
||||
* Returns a set of relations to packages which are recommended in
|
||||
* combination with this package.
|
||||
*
|
||||
* @return array An array of package relations defining recommended packages
|
||||
*/
|
||||
abstract public function getRecommends();
|
||||
|
||||
/**
|
||||
* Returns a set of relations to packages which are suggested in combination
|
||||
* with this package.
|
||||
*
|
||||
* @return array An array of package relations defining suggested packages
|
||||
*/
|
||||
abstract public function getSuggests();
|
||||
|
||||
/**
|
||||
* Converts the package into a readable and unique string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getName().'-'.$this->getReleaseType().'-'.$this->getVersion();
|
||||
}
|
||||
}
|
53
src/Composer/DependencyResolver/PackageRelation.php
Normal file
53
src/Composer/DependencyResolver/PackageRelation.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
*
|
||||
* 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.')';
|
||||
}
|
||||
}
|
25
src/Composer/DependencyResolver/PolicyInterface.php
Normal file
25
src/Composer/DependencyResolver/PolicyInterface.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Composer\DependencyResolver;
|
||||
|
||||
/**
|
||||
* @author Nils Adermann <naderman@naderman.de>
|
||||
*/
|
||||
interface PolicyInterface
|
||||
{
|
||||
function allowUninstall();
|
||||
function allowDowngrade();
|
||||
function versionCompare(Package $a, Package $b, $operator);
|
||||
function findUpdatePackages(Solver $solver, Pool $pool, RepositoryInterface $repo, Package $package, $allowAll);
|
||||
function installable(Solver $solver, Pool $pool, RepositoryInterface $repo, Package $package);
|
||||
function selectPreferedPackages(array $literals);
|
||||
}
|
79
src/Composer/DependencyResolver/Pool.php
Normal file
79
src/Composer/DependencyResolver/Pool.php
Normal file
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* A package pool contains repositories that provide packages.
|
||||
*
|
||||
* @author Nils Adermann <naderman@naderman.de>
|
||||
*/
|
||||
class Pool
|
||||
{
|
||||
protected $repositories = array();
|
||||
protected $packages = array();
|
||||
protected $packageByName = array();
|
||||
|
||||
/**
|
||||
* Adds a repository and its packages to this package pool
|
||||
*
|
||||
* @param RepositoryInterface $repo A package repository
|
||||
*/
|
||||
public function addRepository(RepositoryInterface $repo)
|
||||
{
|
||||
$this->repositories[] = $repo;
|
||||
|
||||
foreach ($repo->getPackages() as $package) {
|
||||
$this->packages[$package->getId()] = $package;
|
||||
|
||||
foreach ($package->getNames() as $name) {
|
||||
if (!isset($this->packageByName[$name])) {
|
||||
$this->packageByNameByName[$name] = array();
|
||||
}
|
||||
|
||||
$this->packageByName[$name][] = $package;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches all packages providing the given package name and match the constraint
|
||||
*
|
||||
* @param string $name The package name to be searched for
|
||||
* @param RelationConstraintInterface $constraint A constraint that all returned
|
||||
* packages must match or null to return all
|
||||
* @return array A set of packages
|
||||
*/
|
||||
public function whatProvides($name, RelationConstraintInterface $constraint = null)
|
||||
{
|
||||
if (!isset($this->packageByName[$name])) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$candidates = $this->packageByName[$name];
|
||||
|
||||
if (null === $constraint) {
|
||||
return $candidates;
|
||||
}
|
||||
|
||||
$result = array();
|
||||
|
||||
foreach ($candidates as $candidate) {
|
||||
if ($candidate->matches($name, $constraint)) {
|
||||
$result[] = $candidate;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Composer\DependencyResolver\RelationConstraint;
|
||||
|
||||
/**
|
||||
* @author Nils Adermann <naderman@naderman.de>
|
||||
*/
|
||||
interface RelationConstraintInterface
|
||||
{
|
||||
function matches($releaseType, $version);
|
||||
function __toString();
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Composer\DependencyResolver\RelationConstraint;
|
||||
|
||||
/**
|
||||
* Constrains a package relation based on package version
|
||||
*
|
||||
* Version numbers must be compatible with version_compare
|
||||
*
|
||||
* @author Nils Adermann <naderman@naderman.de>
|
||||
*/
|
||||
class VersionConstraint implements RelationConstraintInterface
|
||||
{
|
||||
private $operator;
|
||||
private $version;
|
||||
|
||||
/**
|
||||
* Sets operator and version to compare a package with
|
||||
*
|
||||
* @param string $operator A comparison operator
|
||||
* @param string $version A version to compare to
|
||||
*/
|
||||
public function __construct($operator, $version)
|
||||
{
|
||||
$this->operator = $operator;
|
||||
$this->version = $version;
|
||||
}
|
||||
|
||||
public function matches($releaseType, $version)
|
||||
{
|
||||
return version_compare($version, $this->version, $this->operator);
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->operator.' '.$this->version;
|
||||
}
|
||||
}
|
21
src/Composer/DependencyResolver/RepositoryInterface.php
Normal file
21
src/Composer/DependencyResolver/RepositoryInterface.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Composer\DependencyResolver;
|
||||
|
||||
/**
|
||||
* @author Nils Adermann <naderman@naderman.de>
|
||||
*/
|
||||
interface RepositoryInterface extends \Countable
|
||||
{
|
||||
function getPackages();
|
||||
function contains(Package $package);
|
||||
}
|
57
src/Composer/DependencyResolver/Request.php
Normal file
57
src/Composer/DependencyResolver/Request.php
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Composer\DependencyResolver;
|
||||
|
||||
/**
|
||||
* @author Nils Adermann <naderman@naderman.de>
|
||||
*/
|
||||
class Request
|
||||
{
|
||||
protected $jobs;
|
||||
protected $pool;
|
||||
|
||||
public function __construct(Pool $pool)
|
||||
{
|
||||
$this->pool = $pool;
|
||||
}
|
||||
|
||||
public function install($packageName)
|
||||
{
|
||||
$this->addJob($packageName, 'install');
|
||||
}
|
||||
|
||||
public function update($packageName)
|
||||
{
|
||||
$this->addJob($packageName, 'update');
|
||||
}
|
||||
|
||||
public function remove($packageName)
|
||||
{
|
||||
$this->addJob($packageName, 'remove');
|
||||
}
|
||||
|
||||
protected function addJob($packageName, $cmd)
|
||||
{
|
||||
$packages = $this->pool->whatProvides($packageName);
|
||||
|
||||
$this->jobs[] = array(
|
||||
'packages' => $packages,
|
||||
'cmd' => $cmd,
|
||||
'packageName' => $packageName,
|
||||
);
|
||||
}
|
||||
|
||||
public function getJobs()
|
||||
{
|
||||
return $this->jobs;
|
||||
}
|
||||
}
|
161
src/Composer/DependencyResolver/Rule.php
Normal file
161
src/Composer/DependencyResolver/Rule.php
Normal file
|
@ -0,0 +1,161 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Composer\DependencyResolver;
|
||||
|
||||
/**
|
||||
* @author Nils Adermann <naderman@naderman.de>
|
||||
*/
|
||||
class Rule
|
||||
{
|
||||
protected $disabled;
|
||||
protected $literals;
|
||||
protected $type;
|
||||
|
||||
public $watch1;
|
||||
public $watch2;
|
||||
|
||||
public $next1;
|
||||
public $next2;
|
||||
|
||||
public function __construct(array $literals, $reason, $reasonData)
|
||||
{
|
||||
// sort all packages ascending by id
|
||||
usort($literals, array($this, 'compareLiteralsById'));
|
||||
|
||||
$this->literals = $literals;
|
||||
$this->reason = $reason;
|
||||
$this->reasonData = $reasonData;
|
||||
|
||||
$this->disabled = false;
|
||||
|
||||
$this->watch1 = (count($this->literals) > 0) ? $literals[0]->getId() : 0;
|
||||
$this->watch2 = (count($this->literals) > 1) ? $literals[1]->getId() : 0;
|
||||
|
||||
$this->type = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this rule is equal to another one
|
||||
*
|
||||
* Ignores whether either of the rules is disabled.
|
||||
*
|
||||
* @param Rule $rule The rule to check against
|
||||
* @return bool Whether the rules are equal
|
||||
*/
|
||||
public function equals(Rule $rule)
|
||||
{
|
||||
if (count($this->literals) != count($rule->literals)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for ($i = 0, $n = count($this->literals); $i < $n; $i++) {
|
||||
if (!$this->literals[$i]->equals($rule->literals[$i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function setType($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
public function getType($type)
|
||||
{
|
||||
}
|
||||
|
||||
public function disable()
|
||||
{
|
||||
$this->disabled = true;
|
||||
}
|
||||
|
||||
public function enable()
|
||||
{
|
||||
$this->disabled = false;
|
||||
}
|
||||
|
||||
public function isDisabled()
|
||||
{
|
||||
return $this->disabled;
|
||||
}
|
||||
|
||||
public function isEnabled()
|
||||
{
|
||||
return !$this->disabled;
|
||||
}
|
||||
|
||||
public function getLiterals()
|
||||
{
|
||||
return $this->literals;
|
||||
}
|
||||
|
||||
public function isAssertion()
|
||||
{
|
||||
return 1 === count($this->literals);
|
||||
}
|
||||
|
||||
public function getNext(Literal $literal)
|
||||
{
|
||||
if ($this->watch1->equals($literal)) {
|
||||
return $this->next1;
|
||||
} else {
|
||||
return $this->next2;
|
||||
}
|
||||
}
|
||||
|
||||
public function getOtherWatch(Literal $literal)
|
||||
{
|
||||
if ($this->watch1->equals($literal)) {
|
||||
return $this->watch2;
|
||||
} else {
|
||||
return $this->watch1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a rule as a string of the format (Literal1|Literal2|...)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$result = '(';
|
||||
|
||||
foreach ($this->literals as $i => $literal) {
|
||||
if ($i != 0) {
|
||||
$result .= '|';
|
||||
}
|
||||
$result .= $literal;
|
||||
}
|
||||
|
||||
$result .= ')';
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparison function for sorting literals by their id
|
||||
*
|
||||
* @param Literal $a
|
||||
* @param Literal $b
|
||||
* @return int 0 if the literals are equal, 1 if b is larger than a, -1 else
|
||||
*/
|
||||
private function compareLiteralsById(Literal $a, Literal $b)
|
||||
{
|
||||
if ($a->getId() === $b->getId()) {
|
||||
return 0;
|
||||
}
|
||||
return $a->getId() < $b->getId() ? -1 : 1;
|
||||
}
|
||||
}
|
1817
src/Composer/DependencyResolver/Solver.php
Normal file
1817
src/Composer/DependencyResolver/Solver.php
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue