Skip to content

PHP Class that resolves class constant values back to their semantic names.

Notifications You must be signed in to change notification settings

jameshalsall/constant-resolver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

constant-resolver

PHP Class that resolves class constant values back to their semantic names.

Installation

Composer

Add "jameshalsall/constant-resolver" to your composer.json require section.

Usage

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

Example

<?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'
 * );
 */

About

PHP Class that resolves class constant values back to their semantic names.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages