|
|
|
@ -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()
|
|
|
|
|