PHPackages                             philiagus/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. philiagus/enum

Abandoned → PHP8.1 enum implementationLibrary

philiagus/enum
==============

Various implementation of Enums to pick and choose

v2.1.0(3y ago)0413[1 PRs](https://github.com/philiagus/enum/pulls)MITPHPPHP &gt;=8.0CI failing

Since Nov 12Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/philiagus/enum)[ Packagist](https://packagist.org/packages/philiagus/enum)[ RSS](/packages/philiagus-enum/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (5)Dependencies (1)Versions (7)Used By (0)

Enum
====

[](#enum)

Various implementation of Enums to pick and choose

Philiagus\\Enum\\ConstantEnumTrait
----------------------------------

[](#philiagusenumconstantenumtrait)

The ConstantEnumTrait treats every constant available in the class as valid Enum Values of the class. Simply `use` it as a trait in the class you want to use as an Enum. The Trait provides multiple methods:

- `enumAll(): array`

    Lists all the enums of the class as an array. The key is the constant name, the value is the value of the enum.
- `enumHas($value): bool`

    Returns `true` if the provided value is the same as the value of one of the constants of this class.
- `enumAssert($value): void`

    Asserts that the provided value is the same as the value of one of the constants of this class. An `Philiagus\Enum\Exception\InvalidEnumException` is thrown if the provided value is not valid.
- `enumAssertArray(array $values): void`

    Asserts that every element in the array is a valid enum and throws `Philiagus\Enum\Exception\ValuesNotInEnumException` with the invalid values if any are present.

Philiagus\\Enum\\PublicConstantEnumTrait
----------------------------------------

[](#philiagusenumpublicconstantenumtrait)

Works exaclty like the `Philiagus\Enum\ConstantEnumTrait`, but only treats public constants as valid values.

Philiagus\\Enum\\CommentEnum
----------------------------

[](#philiagusenumcommentenum)

This implementation provides Enums that are implementations of the class providing the Enum, so we are talking real Objects here with all the benefits of type-hinting and the likes.

```
