Skip to content
This repository was archived by the owner on Jan 19, 2021. It is now read-only.

codekandis/code-message-interpreter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

codekandis/code-message-interpreter

Version License Minimum PHP Version Code Coverage

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.

Index

Installation

Install the latest version with

$ composer require codekandis/code-message-interpreter

How to use

Define the codes and messages

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 );

Exceptions

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

About

This library interpretes codes into messages based on abstract enumerators.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages