/**
* Adds an individual rule for the given field to the given validator.
* If the $ruleName is numeric the function will assume that $params is the rule name and that there are no
* parameters.
*
* @param string $fieldName
* @param string|int $ruleName
* @param mixed $params
* @param Validator $validator
*
* @since 2.0
*/
protected function addFieldRule($fieldName, $ruleName, $params, Validator $validator)
{
// If $ruleName is numeric assume that $params is the name and there are no actual parameters
if (is_numeric($ruleName)) {
$ruleName = $params;
$params = [];
}
// Create and add the rule
$ruleInstance = $validator->createRuleInstance($ruleName, $params);
$validator->addRule($fieldName, $ruleInstance);
}