Download the PHP package tebru/enum without Composer
On this page you can find all versions of the php package tebru/enum. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Please rate this library. Is it a good library?
Informations about the package enum
Enum
A simple PHP library to add support for enums. This requires slightly more work than myclabs/php-enum, but does not require reflection. It also forces enums to be singletons.
Installation
composer require tebru/enum
Usage
To use, extend AbstractEnum
and implement the getConstants() method.
class DirectionEnum extends AbstractEnum
{
const NORTH = 'north';
const EAST = 'east';
const SOUTH = 'south';
const WEST = 'west';
/**
* Return an array of enum class constants
*
* @return array
*/
public static function getConstants()
{
return [
self::NORTH,
self::EAST,
self::SOUTH,
self::WEST,
];
}
}
Now you can create a new instance using the static method.
DirectionEnum::create('north');
You can also create an instance using the __callStatic magic method.
DirectionEnum::NORTH();
Add a hint to the enum doc block
/**
* @method static $this NORTH()
*/
Reference
There are multiple methods available on each enum
create()
[static] Returns an instance of the enumvalues()
[static] A 0-indexed array of all of the enum valuesexists($value)
[static] Returns true if the value existstoArray()
[static] Returns a hash with keys and values as the enum valuesequals($enum)
Performs a strict comparison of two enum valuesgetValue()
Returns the current value of the enum__toString()
Same asgetValue()
All versions of enum with dependencies
PHP Build Version
Package Version
Requires
php Version
>= 5.4
The package tebru/enum contains the following files
Loading the files please wait ....