/** * @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.'); } }
/** * @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()); }