Ejemplo n.º 1
0
 public function add(Rule $rule, $type)
 {
     if (!isset(self::$types[$type])) {
         throw new \OutOfBoundsException('Unknown rule type: ' . $type);
     }
     $hash = $rule->getHash();
     // Do not add if rule already exists
     if (isset($this->rulesByHash[$hash])) {
         $potentialDuplicates = $this->rulesByHash[$hash];
         foreach ($potentialDuplicates as $potentialDuplicate) {
             if ($rule->equals($potentialDuplicate)) {
                 return;
             }
         }
     }
     if (!isset($this->rules[$type])) {
         $this->rules[$type] = array();
     }
     $this->rules[$type][] = $rule;
     $this->ruleById[$this->nextRuleId] = $rule;
     $rule->setType($type);
     $this->nextRuleId++;
     if (!isset($this->rulesByHash[$hash])) {
         $this->rulesByHash[$hash] = array($rule);
     } else {
         $this->rulesByHash[$hash][] = $rule;
     }
 }
Ejemplo n.º 2
0
 public function add(Rule $rule, $type)
 {
     if (!isset(self::$types[$type])) {
         throw new \OutOfBoundsException('Unknown rule type: ' . $type);
     }
     if (!isset($this->rules[$type])) {
         $this->rules[$type] = array();
     }
     $this->rules[$type][] = $rule;
     $this->ruleById[$this->nextRuleId] = $rule;
     $rule->setType($type);
     $this->nextRuleId++;
     $hash = $rule->getHash();
     if (!isset($this->rulesByHash[$hash])) {
         $this->rulesByHash[$hash] = array($rule);
     } else {
         $this->rulesByHash[$hash][] = $rule;
     }
 }