NOTE: This package is abandoned and no longer maintained. It has been superseded by the package
codekandis/constants-classes-translator
.
With the CodeMessageInterpreter
you are able to translate codes into readable messages. E. g. is useful with third party libraries throwing exceptions with error codes but without meaningful messages.
Install the latest version with
$ composer require codekandis/code-message-interpreter
abstract class ErrorCodes
{
public const ERROR_ONE = 1;
public const ERROR_TWO = 2;
public const ERROR_THREE = 3;
}
abstract class ErrorMessages
{
public const ERROR_ONE = 'Error one occurred.';
public const ERROR_TWO = 'Error two occurred.';
public const ERROR_THREE = 'Error three occurred.';
}
Instantiate and the CodeMessageInterpreter
/** returns 'Error two occurred.' */
( new CodeMessageInterpreter( ErrorCodes::class, ErrorMessages::class ) )
->interpret( ErrorCodes::ERROR_TWO );
The CodeMessageInterpreter
throws an CodeMessageInterpreterException
in several cases.
- the passed codes or messages class names are invalid
- the code to interpret does not exist
- the code to interpret does not have a corresponding message