/** * Sets a parameter by name. * * @param string $key The key * @param mixed $value The value */ public static function set($key, $value) { return \Ape\ParameterBag::set($key, $value); }
/** * Validate a given attribute against a rule. * * @param string $attribute * @param array $rules * * @return bool * @throws \InvalidArgumentException */ protected function validate($attribute, array $rules) { $parsed = new ParameterBag(); $value = array_get($this->data, $attribute); foreach ($rules as $rule) { list($rule, $neg, $parameters) = $this->parseRule($rule); if (!$this->hasValidator($rule)) { throw new \InvalidArgumentException(""); } $validator = $this->getValidator($rule); // TODO: if argument is not required and not given - do not run all rules because in most situations they will fail $status = call_user_func_array($validator, array($attribute, $value, $parameters, $this->data, $parsed)); $parsed->set($rule, array($neg, $parameters)); $status = $neg ? !$status : $status; if (!$status) { // TODO: add failure, then exit $this->addFailure($attribute, $rule, $neg, $parameters); return false; } } return true; }