/** * Get the size of an attribute. * * @param $attribute * @param $value * @param $parameters * @param $source * @param $rules * * @return mixed */ protected function getSize($attribute, $value, $parameters, $source, ParameterBag $rules) { $is_numeric = $rules->has($this->rules_numeric); if ($is_numeric) { // return $value; // If it is a number, then number itself is the size } elseif (is_array($value)) { return count($value); // If it is an array, then elements number is the size } // For the rest entire length of the string will be considered the attribute size. return $this->getStringSize($value); }
/** * Removes a parameter. * * @param string $key The key */ public static function remove($key) { return \Ape\ParameterBag::remove($key); }
/** * 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; }