Download the PHP package dkd/enumeration without Composer
On this page you can find all versions of the php package dkd/enumeration. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download dkd/enumeration
More information about dkd/enumeration
Files in dkd/enumeration
Download dkd/enumeration
More information about dkd/enumeration
Files in dkd/enumeration
Vendor dkd
Package enumeration
Short Description An enumeration implementation for PHP.
License GPL-2.0
Homepage https://github.com/dkd/enumeration
Package enumeration
Short Description An enumeration implementation for PHP.
License GPL-2.0
Homepage https://github.com/dkd/enumeration
Please rate this library. Is it a good library?
Informations about the package enumeration
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.
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 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
- is not build-in into PHP and requires pecl extension installed.
Install
Composer
Add to the project's composer.json dependencies and run
GIT
ZIP / TAR
Download the last version from Github and extract it.
License
This code is also part of the TYPO3 CMS project and has been extracted to this package. See LICENSE for details.
All versions of enumeration with dependencies
PHP Build Version
Package Version
Requires
php Version
>=5.3
The package dkd/enumeration contains the following files
Loading the files please wait ....