kalibora/labeled-enum

Enum with label that extends myclabs/php-enum

v0.2.0 2020-02-05 05:00 UTC

This package is auto-updated.

Last update: 2024-11-05 15:01:26 UTC


README

Enum with label that extends myclabs/php-enum.

Usage

use Kalibora\LabeledEnum\LabeledEnum;

class Fruit extends LabeledEnum
{
    private const APPLE = 1;
    private const ORANGE = 2;
    private const BANANA = 3;

    public static function getLabels() : array
    {
        return [
            self::APPLE => 'Apple',
            self::ORANGE => 'Orange',
            self::BANANA => 'Banana',
        ];
    }
}
$orange = Fruit::ORANGE();

echo $orange->getValue(), PHP_EOL; // 2
echo $orange->getLabal(), PHP_EOL; // Orange