public function contains(Rule $other) { if ($other instanceof NoRule) { return true; } if ($other instanceof NumberRule) { return $this->check($other->getNumber()); } if ($other instanceof static) { return $this->checkMin($other->min) && $this->checkMax($other->max); } return false; }
/** * Add a rule * * @param mixed $rule */ protected function add($rule) { if (is_array($rule)) { foreach ($rule as $subrule) { $this->add($subrule); } return; } if ($rule instanceof Rule) { $this->list[] = $rule; } if (is_numeric($rule)) { $this->list[] = new NumberRule($rule); } if (is_string($rule)) { foreach (explode(',', $rule) as $subrule) { $this->list[] = Rule::create(trim($subrule)); } } }
/** * Check if the requested rule is already contained. * * @param $attribute * @param $rule * @return bool */ public function hasRule($attribute, $rule) { if (!isset($this->rules[$attribute])) { return false; } $rule = Rule::create($rule); foreach ($this->rules[$attribute] as $other) { if ($other->contains($rule)) { return true; } } return false; }