2017 © Pedro Peláez
 

library enumeration

An enumeration implementation for PHP.

image

dkd/enumeration

An enumeration implementation for PHP.

  • Friday, February 20, 2015
  • by sascha.egerer
  • Repository
  • 2 Watchers
  • 0 Stars
  • 13,044 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 8 % Grown

The README.md

PHP Enumeration

This is a native PHP implementation to add enumeration support to PHP >= 5.3. It's an abstract class that needs to be extended to use it., (*1)

Usage

Basics

use Dkd\Enumeration;

class MyEnumeration extends Enumeration
{
    // this is optional. The value will be used as default value if no value
    // is given.
    const __DEFAULT = self::INTEGER_VALUE;

    // all scalar datatypes are supported
    const INTEGER_VALUE = 1;
    const FLOAT_VALUE = 0.123;
    const STRING_VALUE = 'foo';
    const BOOLEAN_VALUE = true;
}

// Use the ```__DEFAULT``` value if defined. If not defined an exception
// is thrown.
$myEnumeration = MyEnumeration();

$myEnumeration = new MyEnumeration(MyEnumeration::INTEGER_VALUE);

// cast does automatically cast the given value to the enumeration value.
$myEnumeration = MyEnumeration::cast(MyEnumeration::INTEGER_VALUE);
$myEnumeration = MyEnumeration::cast($myEnumeration);
$myEnumeration = MyEnumeration::cast($databaseResult['my_column']);

// get all possible values of the enumeration.
$possibleValues = MyEnumeration::getConstants();

$myEnumeration = new MyEnumeration(MyEnumeration::INTEGER_VALUE);
$myEnumeration->equals(1); // TRUE
$myEnumeration->equals($myEnumeration); // TRUE
$myEnumeration->equals(0.123); // FALSE
$myEnumeration->equals('foo'); // FALSE
$myEnumeration->equals(new MyEnumeration('foo')); // FALSE

Why not SplEnum

  • SplEnum is not build-in into PHP and requires pecl extension installed.

Install

Composer

Add dkd/enumeration to the project's composer.json dependencies and run php composer.phar install, (*2)

GIT

git clone git://github.com/dkd/enumeration.git, (*3)

ZIP / TAR

Download the last version from Github and extract it., (*4)

License

This code is also part of the TYPO3 CMS project and has been extracted to this package. See LICENSE for details., (*5)

The Versions

20/02 2015

dev-master

9999999-dev https://github.com/dkd/enumeration

An enumeration implementation for PHP.

  Sources   Download

GPL-2.0

The Requires

  • php >=5.3

 

The Development Requires

enum type enumeration

28/08 2014

0.1

0.1.0.0 https://github.com/dkd/enumeration

An enumeration implementation for PHP.

  Sources   Download

GPL-2.0

The Requires

  • php >=5.3

 

The Development Requires

enum type enumeration