示例#1
0
文件: Ruling.php 项目: subzeta/ruling
 /**
  * @throws InvalidContextException
  * @throws InvalidRuleException
  * @throws InvalidCallbackException
  */
 private function validate()
 {
     if (!$this->context->valid()) {
         throw new InvalidContextException('Context must be an array with string keys and values.');
     }
     if (!$this->rules->valid()) {
         throw new InvalidRuleException('Rule must be a string or an array of strings.');
     }
     if (!$this->evaluator->valid($this->rules, $this->context)) {
         throw new InvalidRuleException('Rules aren\'t semantically valid (' . implode(',', $this->interpret()) . ').');
     }
     if ($this->successCallback !== null && !is_callable($this->successCallback)) {
         throw new InvalidCallbackException('Success callback must be callable.');
     }
     if ($this->failCallback !== null && !is_callable($this->failCallback)) {
         throw new InvalidCallbackException('Fail callback must be callable.');
     }
 }
示例#2
0
 /**
  * @param RuleCollection $rules
  * @param Context $context
  * @return string[]
  */
 private function build($rules, $context)
 {
     return array_map(function ($rule) use($context) {
         return $this->prepare($rule, $context);
     }, $rules->get());
 }