PHPackages                             wscore/enum - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. wscore/enum

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

wscore/enum
===========

Enumerated class.

1.0.0(8y ago)024[2 issues](https://github.com/WScore/Enum/issues)MITPHP

Since Aug 27Pushed 8y ago1 watchersCompare

[ Source](https://github.com/WScore/Enum)[ Packagist](https://packagist.org/packages/wscore/enum)[ RSS](/packages/wscore-enum/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (5)Used By (0)

Enumerated Class
================

[](#enumerated-class)

Enum and list implementation

### Licence

[](#licence)

MIT License

### Installation

[](#installation)

```
composer require "wscore/enum: ^1.0"
```

Sample Code
-----------

[](#sample-code)

### create a EnumList class

[](#create-a-enumlist-class)

The intended way of creating a enumerated class is,

1. define constants,
2. define static `$choices` array.

as in the example below.

```
use WScore\Enum\AbstractEnum;

class EnumList extends AbstractEnum
{
    const ENUM = 'enum';
    const VALUE = 'value';

    protected static $choices = [
        self::ENUM => 'enumerated',
        self::VALUE => 'value',
    ];
}
```

The `$choices` variable defines available values along side with labels (i.e. human readable string).

### get enumerated object

[](#get-enumerated-object)

static function, `enum`, returns an instantiated enumerated object, which is `EnumInterface`

```
$enum = EnumList::enum(EnumList::ENUM);
(string) $enum; // enum
$enum->label(); // enumerated
$enum->is(EnumList::ENUM); // true
```

### enum list and keys

[](#enum-list-and-keys)

Use static methods such as, `choices()`, `keys()`, or `flipped()`, to get the list of available enum values and keys, that may be used for validating inputs.

```
$list = EnumList::choices(); // returns list of keys and labels.
$keys = EnumList::keys();    // returns keys of enumerated list.
$flip = EnumList::flipped(); // returns array of key/value flipped.
```

subset of choices
-----------------

[](#subset-of-choices)

In some use cases, you may need to restrict the selectable values. For instance, the `ActiveList` class below, has 3 statuses but may want to restrict to only 2 options for the end-user, as defined in in `userChoice`.

```
class ActiveList extends AbstractEnum
{
    const ACTIVE = 'active';
    const CANCEL = 'cancel';
    const HOLD   = 'hold';

    protected static $choices = [
        self::ACTIVE => 'activated',
        self::CANCEL => 'canceled',
        self::HOLD   => 'hold-on',
    ];

    /**
     * @return array
     */
    public static function userChoice()
    {
        return [
            self::ACTIVE => 'activated',
            self::CANCEL => 'canceled',
        ];
    }
}
```

To get the available choices,

```
$list = ActiveList::userChoice();
$keys = ActiveList::keys('userChoice');
$flip = ActiveList::flipped('userChoice');
```

### really restricting use of list

[](#really-restricting-use-of-list)

To really limit choices to the subset of the original `static::$choices`...

```
use WScore\Enum\AbstractEnum;

class EnumList extends AbstractEnum
{
    const ENUM = 'enum';
    const VALUE = 'value';
    protected static $choices = [
        self::ENUM => 'enumerated',
        self::VALUE => 'value',
    ];

    /**
     * @param string $value
     * @return EnumList
     */
    public static function getUserEnum($value)
    {
        $choices = self::$choices;
        unset($choices[self::VALUE]);
        return new EnumList($value, $choices);
    }
}
```

then, the following code will throw an \\InvalidArgumentException.

```
$enum = EnumList::getUserEnum(EnumList::VALUE);
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~24 days

Total

4

Last Release

3108d ago

Major Versions

0.2.1 → 1.0.02017-11-10

### Community

Maintainers

![](https://www.gravatar.com/avatar/8ed783829e6fa0bd4b0def8c04ccfdfb2fc99f9e61e4a9470acad9e5abc5fcac?d=identicon)[asaokamei](/maintainers/asaokamei)

---

Top Contributors

[![asaokamei](https://avatars.githubusercontent.com/u/747030?v=4)](https://github.com/asaokamei "asaokamei (11 commits)")

### Embed Badge

![Health badge](/badges/wscore-enum/health.svg)

```
[![Health](https://phpackages.com/badges/wscore-enum/health.svg)](https://phpackages.com/packages/wscore-enum)
```

###  Alternatives

[awcodes/filament-badgeable-column

Filament Tables column to append and prepend badges.

142419.3k3](/packages/awcodes-filament-badgeable-column)[metaregistrar/php-dns-client

A php-only, object-oriented client that is able to read and process DNS records

297.6k](/packages/metaregistrar-php-dns-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
