示例#1
0
文件: Rules.php 项目: bazo/Mokuji
 /**
  * Adds a validation rule for the current control.
  * @param  mixed      rule type
  * @param  string     message to display for invalid data
  * @param  mixed      optional rule arguments
  * @return Rules      provides a fluent interface
  */
 public function addRule($operation, $message = NULL, $arg = NULL)
 {
     $rule = new Rule();
     $rule->control = $this->control;
     $rule->operation = $operation;
     $this->adjustOperation($rule);
     $rule->arg = $arg;
     $rule->type = Rule::VALIDATOR;
     if ($message === NULL && isset(self::$defaultMessages[$rule->operation])) {
         $rule->message = self::$defaultMessages[$rule->operation];
     } else {
         $rule->message = $message;
     }
     if ($this->parent === NULL) {
         // notify only direct rules
         $this->control->notifyRule($rule);
     }
     $this->rules[] = $rule;
     return $this;
 }
示例#2
0
 /**
  * Adds a validation condition on specified control a returns new branch.
  * @param  IFormControl form control
  * @param  mixed      condition type
  * @param  mixed      optional condition arguments
  * @return Rules      new branch
  */
 public function addConditionOn(IFormControl $control, $operation, $arg = NULL)
 {
     $rule = new Rule();
     $rule->control = $control;
     $rule->operation = $operation;
     $this->adjustOperation($rule);
     $rule->arg = $arg;
     $rule->type = Rule::CONDITION;
     $rule->subRules = new self($this->control);
     $control->notifyRule($rule);
     $this->rules[] = $rule;
     return $rule->subRules;
 }