PHP Class that resolves class constant values back to their semantic names.
Add "jameshalsall/constant-resolver" to your composer.json require section.
Example class:
<?php
class SomeClass
{
const MY_CONSTANT_NAME = 1;
...
}
<?php
use JamesHalsall\ConstantResolver;
$someClass = new SomeClass();
$resolver = new ConstantResolver($someClass);
// returns 'SomeClass::MY_CONSTANT_NAME'
$constant = $resolver->resolve(1);
<?php
$httpErrorCodes = new HttpErrorCodes();
$resolver = new ConstantResolver($enumerableClass);
// returns 'HttpErrorCodes::NOT_FOUND'
$resolver->resolve(404);
Same example with array return:
<?php
...
$resolver->setReturnType(ConstantResolver::RETURN_ARRAY);
/**
* returns array(
* 'NOT_FOUND' => 'HttpErrorCodes::NOT_FOUND'
* );
*/