Ejemplo n.º 1
0
 /**
  * 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));
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }