codekandis/constants-classes-translator
is a library to translate values from constants classes into values of another constants classes.
Install the latest version with
$ composer require codekandis/constants-classes-translator
Test the code with
$ composer test
abstract class ErrorCodes
{
public const int ERROR_ONE = 1;
public const int ERROR_TWO = 2;
public const int ERROR_THREE = 3;
}
abstract class ErrorMessages
{
public const string ERROR_ONE = 'Error one occurred.';
public const string ERROR_TWO = 'Error two occurred.';
public const string ERROR_THREE = 'Error three occurred.';
}
Instantiate the ConstantsClassesTranslator
( new ConstantsClassesTranslator( ErrorCodes::class, ErrorMessages::class ) )
->translate( ErrorCodes::ERROR_TWO );
/**
* Error two occured.
*/
or vice versa
( new ConstantsClassesTranslator( ErrorMessages::class, ErrorCodes::class ) )
->translate( ErrorMessages::ERROR_TWO );
/**
* 2
*/
The ConstantsClassesTranslator
throws several exceptions which inherits from ConstantsClassesTranslatorException
.
ConstantsClassNotFoundException
the passed constants class name does not existCorrespondingConstantsClassValueNotFoundException
the constants class value has no corresponding constants class valueConstantsClassValueNotFoundException
the constants class value does not exist