Wallogit.com
2017 © Pedro Peláez
Simple enumeration library
Just another PHP enumeration library, (*2)
Prefered way to install library is with composer:, (*3)
composer require kambo/enum
Enumeration is declared by implementing class Kambo\Enum\Enum and adding class constants:, (*4)
use Kambo\Enum\Enum;
class Foo extends Enum {
const BAR = 'bar';
const QUX = 'qux';
}
Base enum class implement following usefull methods:, (*5)
toArray convert whole enumeration to array with constant name in key and Enum instance in value, (*6)
Following example code:, (*7)
$array = Foo::toArray(); var_dump($array);
Will print:, (*8)
array(2) {
'BAR' =>
string(3) "bar"
'QUX' =>
string(3) "qux"
}
There is also alias method called values which just called toArray method., (*9)
inEnum check if the provided value is in enumeration:, (*10)
$existInEnum = Foo::inEnum('bar');
// print true as the value exists in enumeration
echo $existInEnum;
$existInEnum = Foo::inEnum('agh');
// print false as the value does not exists in enumeration
echo $existInEnum;
The MIT License (MIT), https://opensource.org/licenses/MIT, (*11)