Completed analysis of unsolvable situations and main decision process
parent
49c3446ac1
commit
825deff09f
|
@ -59,9 +59,41 @@ class DefaultPolicy implements PolicyInterface
|
|||
return true;
|
||||
}
|
||||
|
||||
public function selectPreferedPackages(array $literals)
|
||||
public function selectPreferedPackages(Solver $solver, Pool $pool, RepositoryInterface $installed, array $literals)
|
||||
{
|
||||
// todo: prefer installed, recommended, highest priority repository, ...
|
||||
return array($literals[0]);
|
||||
// prefer installed, newest version, recommended, highest priority repository, ...
|
||||
$newest = $this->selectNewestPackages($installed, $literals);
|
||||
|
||||
$selected = array();
|
||||
foreach ($newest as $literal) {
|
||||
if ($literal->getPackage()->getRepository() === $installed) {
|
||||
$selected[] = $literal;
|
||||
}
|
||||
}
|
||||
if (count($selected)) {
|
||||
return $selected;
|
||||
}
|
||||
|
||||
return $newest;
|
||||
}
|
||||
|
||||
public function selectNewestPackages(RepositoryInterface $installed, array $literals)
|
||||
{
|
||||
$maxLiterals = array($literals[0]);
|
||||
$maxPackage = $literals[0]->getPackage();
|
||||
foreach ($literals as $i => $literal) {
|
||||
if (0 === $i) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->versionCompare($literal->getPackage(), $maxPackage, '>')) {
|
||||
$maxPackage = $literal->getPackage();
|
||||
$maxLiterals = array($literal);
|
||||
} else if ($this->versionCompare($literal->getPackage(), $maxPackage, '==')) {
|
||||
$maxLiterals[] = $literal;
|
||||
}
|
||||
}
|
||||
|
||||
return $maxLiterals;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,5 +25,5 @@ interface PolicyInterface
|
|||
function versionCompare(PackageInterface $a, PackageInterface $b, $operator);
|
||||
function findUpdatePackages(Solver $solver, Pool $pool, RepositoryInterface $repo, PackageInterface $package, $allowAll);
|
||||
function installable(Solver $solver, Pool $pool, RepositoryInterface $repo, PackageInterface $package);
|
||||
function selectPreferedPackages(array $literals);
|
||||
function selectPreferedPackages(Solver $solver, Pool $pool, RepositoryInterface $installed, array $literals);
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ class Pool
|
|||
|
||||
foreach ($repo->getPackages() as $package) {
|
||||
$this->packages[] = $package;
|
||||
$package->setId(sizeof($this->packages));
|
||||
$package->setId(sizeof($this->packages) - 1);
|
||||
|
||||
foreach ($package->getNames() as $name) {
|
||||
$this->packageByName[$name][] = $package;
|
||||
|
|
|
@ -20,6 +20,8 @@ class Rule
|
|||
protected $disabled;
|
||||
protected $literals;
|
||||
protected $type;
|
||||
protected $id;
|
||||
protected $weak;
|
||||
|
||||
public $watch1;
|
||||
public $watch2;
|
||||
|
@ -37,6 +39,7 @@ class Rule
|
|||
$this->reasonData = $reasonData;
|
||||
|
||||
$this->disabled = false;
|
||||
$this->weak = false;
|
||||
|
||||
$this->watch1 = (count($this->literals) > 0) ? $literals[0]->getId() : 0;
|
||||
$this->watch2 = (count($this->literals) > 1) ? $literals[1]->getId() : 0;
|
||||
|
@ -44,6 +47,16 @@ class Rule
|
|||
$this->type = -1;
|
||||
}
|
||||
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this rule is equal to another one
|
||||
*
|
||||
|
@ -97,6 +110,16 @@ class Rule
|
|||
return !$this->disabled;
|
||||
}
|
||||
|
||||
public function isWeak()
|
||||
{
|
||||
return $this->weak;
|
||||
}
|
||||
|
||||
public function setWeak($weak)
|
||||
{
|
||||
$this->weak = $weak;
|
||||
}
|
||||
|
||||
public function getLiterals()
|
||||
{
|
||||
return $this->literals;
|
||||
|
|
|
@ -15,14 +15,14 @@ namespace Composer\DependencyResolver;
|
|||
/**
|
||||
* @author Nils Adermann <naderman@naderman.de>
|
||||
*/
|
||||
class RuleSet
|
||||
class RuleSet implements \IteratorAggregate, \Countable
|
||||
{
|
||||
// highest priority => lowest number
|
||||
const TYPE_PACKAGE = 0;
|
||||
const TYPE_JOB = 1;
|
||||
const TYPE_UPDATE = 2;
|
||||
const TYPE_FEATURE = 3;
|
||||
const TYPE_WEAK = 4;
|
||||
const TYPE_CHOICE = 4;
|
||||
const TYPE_LEARNED = 5;
|
||||
|
||||
protected static $types = array(
|
||||
|
@ -31,14 +31,18 @@ class RuleSet
|
|||
self::TYPE_FEATURE => 'FEATURE',
|
||||
self::TYPE_UPDATE => 'UPDATE',
|
||||
self::TYPE_JOB => 'JOB',
|
||||
self::TYPE_WEAK => 'WEAK',
|
||||
self::TYPE_CHOICE => 'CHOICE',
|
||||
self::TYPE_LEARNED => 'LEARNED',
|
||||
);
|
||||
|
||||
protected $rules;
|
||||
protected $ruleById;
|
||||
protected $nextRuleId;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->nextRuleId = 0;
|
||||
|
||||
foreach ($this->getTypes() as $type) {
|
||||
$this->rules[$type] = array();
|
||||
}
|
||||
|
@ -46,18 +50,30 @@ class RuleSet
|
|||
|
||||
public function add(Rule $rule, $type)
|
||||
{
|
||||
if (!isset(self::$types[$type]))
|
||||
{
|
||||
if (!isset(self::$types[$type])) {
|
||||
throw OutOfBoundsException('Unknown rule type: ' . $type);
|
||||
}
|
||||
|
||||
if (!isset($this->rules[$type]))
|
||||
{
|
||||
if (!isset($this->rules[$type])) {
|
||||
$this->rules[$type] = array();
|
||||
}
|
||||
|
||||
$this->rules[$type][] = $rule;
|
||||
$this->ruleById[$this->nextRuleId] = $rule;
|
||||
$rule->setType($type);
|
||||
|
||||
$rule->setId($this->nextRuleId);
|
||||
$this->nextRuleId++;
|
||||
}
|
||||
|
||||
public function count()
|
||||
{
|
||||
return $this->nextRuleId;
|
||||
}
|
||||
|
||||
public function ruleById($id)
|
||||
{
|
||||
return $this->ruleById[$id];
|
||||
}
|
||||
|
||||
public function getRules()
|
||||
|
|
|
@ -21,7 +21,6 @@ class RuleSetIterator implements \Iterator
|
|||
protected $types;
|
||||
|
||||
protected $currentOffset;
|
||||
protected $currentTotalOffset;
|
||||
protected $currentType;
|
||||
protected $currentTypeOffset;
|
||||
|
||||
|
@ -44,14 +43,8 @@ class RuleSetIterator implements \Iterator
|
|||
return $this->currentType;
|
||||
}
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return $this->currentTotalOffset;
|
||||
}
|
||||
|
||||
public function next()
|
||||
{
|
||||
$this->currentTotalOffset++;
|
||||
$this->currentOffset++;
|
||||
|
||||
if (!isset($this->rules[$this->currentType])) {
|
||||
|
@ -77,7 +70,6 @@ class RuleSetIterator implements \Iterator
|
|||
public function rewind()
|
||||
{
|
||||
$this->currentOffset = 0;
|
||||
$this->currentTotalOffset = 0;
|
||||
|
||||
$this->currentTypeOffset = -1;
|
||||
$this->currentType = -1;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -29,8 +29,8 @@ class RuleSetTest extends \PHPUnit_Framework_TestCase
|
|||
new Rule(array(), 'update1', null),
|
||||
),
|
||||
RuleSet::TYPE_FEATURE => array(),
|
||||
RuleSet::TYPE_WEAK => array(),
|
||||
RuleSet::TYPE_LEARNED => array(),
|
||||
RuleSet::TYPE_CHOICE => array(),
|
||||
);
|
||||
|
||||
$ruleSet = new RuleSet;
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
namespace Composer\Test\DependencyResolver;
|
||||
|
||||
use Composer\Repository\ArrayRepository;
|
||||
use Composer\Repository\PlatformRepository;
|
||||
use Composer\DependencyResolver\DefaultPolicy;
|
||||
use Composer\DependencyResolver\Pool;
|
||||
use Composer\DependencyResolver\Request;
|
||||
|
@ -29,7 +30,7 @@ class SolverTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
$repoInstalled = new ArrayRepository;
|
||||
$repoInstalled->addPackage($oldPackage = new MemoryPackage('old', '1.0'));
|
||||
$repoInstalled->addPackage(new MemoryPackage('C', '1.0'));
|
||||
$repoInstalled->addPackage($oldPackageC = new MemoryPackage('C', '1.0'));
|
||||
|
||||
$repo = new ArrayRepository;
|
||||
$repo->addPackage($packageA = new MemoryPackage('A', '2.0'));
|
||||
|
@ -44,8 +45,8 @@ class SolverTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
$request = new Request($pool);
|
||||
$request->install('A');
|
||||
$request->update('C');
|
||||
$request->remove('old');
|
||||
//$request->update('C');
|
||||
//$request->remove('old');
|
||||
|
||||
$policy = new DefaultPolicy;
|
||||
$solver = new Solver($policy, $pool, $repoInstalled);
|
||||
|
@ -56,15 +57,15 @@ class SolverTest extends \PHPUnit_Framework_TestCase
|
|||
'job' => 'install',
|
||||
'package' => $packageA,
|
||||
),
|
||||
array(
|
||||
/*array(
|
||||
'job' => 'remove',
|
||||
'package' => $oldPackage,
|
||||
),
|
||||
),*/
|
||||
array(
|
||||
'job' => 'install',
|
||||
'package' => $newPackageB,
|
||||
),
|
||||
/* array(
|
||||
'package' => $packageB,
|
||||
),/*
|
||||
array(
|
||||
'job' => 'update',
|
||||
'package' => $packageC,
|
||||
),*/
|
||||
|
|
Loading…
Reference in New Issue