mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-30 23:01:52 +00:00
Allow disabling of auto prepending the field labels shown in the error message.
This commit is contained in:
parent
9268adeeb4
commit
128097ea16
@ -83,6 +83,11 @@ class Validator
|
|||||||
*/
|
*/
|
||||||
protected $stop_on_first_fail = false;
|
protected $stop_on_first_fail = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $prepend_labels = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup validation
|
* Setup validation
|
||||||
*
|
*
|
||||||
@ -144,6 +149,14 @@ class Validator
|
|||||||
return static::$_langDir ?: dirname(dirname(__DIR__)) . '/lang';
|
return static::$_langDir ?: dirname(dirname(__DIR__)) . '/lang';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param bool $prepend_labels
|
||||||
|
*/
|
||||||
|
public function prependLabels($prepend_labels = true)
|
||||||
|
{
|
||||||
|
$this->prepend_labels = $prepend_labels;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Required field validator
|
* Required field validator
|
||||||
*
|
*
|
||||||
@ -900,6 +913,12 @@ class Validator
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $field
|
||||||
|
* @param $value
|
||||||
|
* @param $params
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
protected function validateInstanceOf($field, $value, $params)
|
protected function validateInstanceOf($field, $value, $params)
|
||||||
{
|
{
|
||||||
$isInstanceOf = false;
|
$isInstanceOf = false;
|
||||||
@ -1022,6 +1041,12 @@ class Validator
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $field
|
||||||
|
* @param $value
|
||||||
|
* @param $params
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
protected function validateArrayHasKeys($field, $value, $params)
|
protected function validateArrayHasKeys($field, $value, $params)
|
||||||
{
|
{
|
||||||
if (!is_array($value) || !isset($params[0])) {
|
if (!is_array($value) || !isset($params[0])) {
|
||||||
@ -1124,6 +1149,12 @@ class Validator
|
|||||||
$this->_labels = array();
|
$this->_labels = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $data
|
||||||
|
* @param $identifiers
|
||||||
|
* @param bool $allow_empty
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
protected function getPart($data, $identifiers, $allow_empty = false)
|
protected function getPart($data, $identifiers, $allow_empty = false)
|
||||||
{
|
{
|
||||||
// Catches the case where the field is an array of discrete values
|
// Catches the case where the field is an array of discrete values
|
||||||
@ -1167,6 +1198,13 @@ class Validator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $validation
|
||||||
|
* @param $field
|
||||||
|
* @param $values
|
||||||
|
* @param $multiple
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
private function validationMustBeExcecuted($validation, $field, $values, $multiple){
|
private function validationMustBeExcecuted($validation, $field, $values, $multiple){
|
||||||
//always excecute requiredWith(out) rules
|
//always excecute requiredWith(out) rules
|
||||||
if (in_array($validation['rule'], array('requiredWith', 'requiredWithout'))){
|
if (in_array($validation['rule'], array('requiredWith', 'requiredWithout'))){
|
||||||
@ -1288,6 +1326,9 @@ class Validator
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $callback
|
||||||
|
*/
|
||||||
protected static function assertRuleCallback($callback)
|
protected static function assertRuleCallback($callback)
|
||||||
{
|
{
|
||||||
if (!is_callable($callback)) {
|
if (!is_callable($callback)) {
|
||||||
@ -1471,7 +1512,9 @@ class Validator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$message = str_replace('{field}', ucwords(str_replace('_', ' ', $field)), $message);
|
$message = $this->prepend_labels
|
||||||
|
? str_replace('{field}', ucwords(str_replace('_', ' ', $field)), $message)
|
||||||
|
: str_replace('{field} ', '', $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $message;
|
return $message;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user