utilitte/enum

There is no license information available for the latest version (v2.0.0) of this package.

Maintainers

Details

github.com/utilitte/enum

Source

Issues

Installs: 712

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/utilitte/enum

v2.0.0 2020-10-13 10:03 UTC

This package is auto-updated.

Last update: 2025-09-13 20:48:13 UTC


README

Type safe enums

Getting started

Create enum class

/**
 * @method static self ENGLAND() 
 * @method static self USA() 
 */
class CountryEnum extends Enum
{
    protected static function getEnums(): array
    {
        return ['england', 'usa'];
    }

}

Usage

static method must be always uppercase

assert(CountryEnum::USA() === CountryEnum::USA());

function country(CountryEnum $country): string {
    return $country->value();
}

assert(country(CountryEnum::USA()) === 'usa');

convert enum value to object:

assert(CountryEnum::get('usa') === CountryEnum::USA());