2017 © Pedro Peláez
 

library enum

Simple enumeration library

image

kambo/enum

Simple enumeration library

  • Sunday, November 27, 2016
  • by kambo
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1,519 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 19 % Grown

The README.md

Kambo PHP enum library

Build Status Scrutinizer Code Quality Code Coverage Software License, (*1)

Just another PHP enumeration library, (*2)

Install

Prefered way to install library is with composer:, (*3)

composer require kambo/enum

Usage

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;

License

The MIT License (MIT), https://opensource.org/licenses/MIT, (*11)

The Versions

27/11 2016

dev-master

9999999-dev

Simple enumeration library

  Sources   Download

MIT

The Requires

  • php >=5.5

 

by Bohuslav Simek

enumeration