Jet\Validator_ErrorMessageGenerator

Abstract class forming the basis of validator error message generators.

The generator serves, for example, for the correct translation of error messages—meaning integration with the translator, but not limited to it. Generating error messages can be custom implemented according to your specific needs.

Method Description
public setValidator(
Validator $validator
) : void
Sets the validator instance in whose context the generator will operate.
public getValidator(
) : Validator
Returns the validator instance in whose context the generator is currently operating.
public generateErrorMessage(
string $error_code,
array $error_data
) : string
Generates an error message based on the error code and error data. The default generator implementation has the following form: public function generateErrorMessage( string $error_code, array $error_data ): string
{
    
$error_message = $this->validator->getErrorMessages()[$error_code]??$error_code;
    
    return 
Tr::_($error_message, $error_data);
}
Previous chapter
Jet\Validator
Next chapter
Jet\Validator_ValidationError