|
|
@ -39,6 +39,8 @@ class RuleSet implements \IteratorAggregate, \Countable
|
|
|
|
protected $ruleById;
|
|
|
|
protected $ruleById;
|
|
|
|
protected $nextRuleId;
|
|
|
|
protected $nextRuleId;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected $rulesByHash;
|
|
|
|
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$this->nextRuleId = 0;
|
|
|
|
$this->nextRuleId = 0;
|
|
|
@ -46,6 +48,8 @@ class RuleSet implements \IteratorAggregate, \Countable
|
|
|
|
foreach ($this->getTypes() as $type) {
|
|
|
|
foreach ($this->getTypes() as $type) {
|
|
|
|
$this->rules[$type] = array();
|
|
|
|
$this->rules[$type] = array();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->rulesByHash = array();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function add(Rule $rule, $type)
|
|
|
|
public function add(Rule $rule, $type)
|
|
|
@ -64,6 +68,13 @@ class RuleSet implements \IteratorAggregate, \Countable
|
|
|
|
|
|
|
|
|
|
|
|
$rule->setId($this->nextRuleId);
|
|
|
|
$rule->setId($this->nextRuleId);
|
|
|
|
$this->nextRuleId++;
|
|
|
|
$this->nextRuleId++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$hash = $rule->getHash();
|
|
|
|
|
|
|
|
if (!isset($this->rulesByHash[$hash])) {
|
|
|
|
|
|
|
|
$this->rulesByHash[$hash] = array($rule);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$this->rulesByHash[$hash][] = $rule;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function count()
|
|
|
|
public function count()
|
|
|
@ -129,6 +140,20 @@ class RuleSet implements \IteratorAggregate, \Countable
|
|
|
|
return array_keys($types);
|
|
|
|
return array_keys($types);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function containsEqual($rule)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (isset($this->rulesByHash[$rule->getHash()])) {
|
|
|
|
|
|
|
|
$potentialDuplicates = $this->rulesByHash[$rule->getHash()];
|
|
|
|
|
|
|
|
foreach ($potentialDuplicates as $potentialDuplicate) {
|
|
|
|
|
|
|
|
if ($rule->equals($potentialDuplicate)) {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function __toString()
|
|
|
|
public function __toString()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$string = "\n";
|
|
|
|
$string = "\n";
|
|
|
|