aeviiq/enum

Enum Component

v4.0 2023-12-14 12:32 UTC

This package is auto-updated.

Last update: 2024-11-14 14:51:36 UTC


README

Why

To provide a way to implement enum flags in PHP.

Installation

composer require aeviiq/enum

Declaration

final class Foo extends AbstractFlag
{
    public const BAR = 1;
    public const BAZ = 2;
    // ...
}

Usage

$foo = new Foo(Foo:BAR);
$foo->contains(new Foo(Foo:BAR)); // True
$foo->contains(new Foo(Foo:BAZ)); // False
$foo->contains(new Bar(Foo::BAR)); // InvalidArgumentException thrown
$foo = new Foo(6); // UnexpectedValueException thrown