PHP code example of jameshalsall / constant-resolver
1. Go to this page and download the library: Download jameshalsall/constant-resolver library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jameshalsall / constant-resolver example snippets
` 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);
` php
...
$resolver->setReturnType(ConstantResolver::RETURN_ARRAY);
/**
* returns array(
* 'NOT_FOUND' => 'HttpErrorCodes::NOT_FOUND'
* );
*/