added array and array count validation
added validate_array/count/countmin/countmax/countbetween - corresponding replace_count/countmin/countmax/countbetween message functions - corresponding validator error messages into all language files (please have maintainers update their language files) - also converted spaces to tabs in the polish language file to fit all the others.
This commit is contained in:
@@ -667,6 +667,70 @@ class Validator {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that an attribute is an array
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
protected function validate_array($attribute, $value)
|
||||
{
|
||||
return is_array($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that an attribute of type array has a specific count
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @param array $parameters
|
||||
* @return bool
|
||||
*/
|
||||
protected function validate_count($attribute, $value, $parameters)
|
||||
{
|
||||
return (is_array($value) && count($value) == $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that an attribute of type array has a minimum of elements.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @param array $parameters
|
||||
* @return bool
|
||||
*/
|
||||
protected function validate_countmin($attribute, $value, $parameters)
|
||||
{
|
||||
return (is_array($value) && count($value) >= $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that an attribute of type array has a maximum of elements.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @param array $parameters
|
||||
* @return bool
|
||||
*/
|
||||
protected function validate_countmax($attribute, $value, $parameters)
|
||||
{
|
||||
return (is_array($value) && count($value) <= $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that an attribute of type array has elements between max and min.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @param array $parameters
|
||||
* @return bool
|
||||
*/
|
||||
protected function validate_countbetween($attribute, $value, $parameters)
|
||||
{
|
||||
return (is_array($value) && count($value) >= $parameters[0] && count($value) <= $parameters[1] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the date is before a given date.
|
||||
*
|
||||
@@ -952,6 +1016,62 @@ class Validator {
|
||||
return str_replace(':date', $parameters[0], $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace all place-holders for the count rule.
|
||||
*
|
||||
* @param string $message
|
||||
* @param string $attribute
|
||||
* @param string $rule
|
||||
* @param array $parameters
|
||||
* @return string
|
||||
*/
|
||||
protected function replace_count($message, $attribute, $rule, $parameters)
|
||||
{
|
||||
return str_replace(':count', $parameters, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace all place-holders for the countmin rule.
|
||||
*
|
||||
* @param string $message
|
||||
* @param string $attribute
|
||||
* @param string $rule
|
||||
* @param array $parameters
|
||||
* @return string
|
||||
*/
|
||||
protected function replace_countmin($message, $attribute, $rule, $parameters)
|
||||
{
|
||||
return str_replace(':min', $parameters, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace all place-holders for the countmax rule.
|
||||
*
|
||||
* @param string $message
|
||||
* @param string $attribute
|
||||
* @param string $rule
|
||||
* @param array $parameters
|
||||
* @return string
|
||||
*/
|
||||
protected function replace_countmax($message, $attribute, $rule, $parameters)
|
||||
{
|
||||
return str_replace(':max', $parameters, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace all place-holders for the between rule.
|
||||
*
|
||||
* @param string $message
|
||||
* @param string $attribute
|
||||
* @param string $rule
|
||||
* @param array $parameters
|
||||
* @return string
|
||||
*/
|
||||
protected function replace_countbetween($message, $attribute, $rule, $parameters)
|
||||
{
|
||||
return str_replace(array(':min', ':max'), $parameters, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the displayable name for a given attribute.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user