Skip to content

1.1 (added initialization enum from value)

Latest
Compare
Choose a tag to compare
@Ne-Lexa Ne-Lexa released this 07 Nov 10:34
· 6 commits to master since this release

Added new method Enum::fromValue(mixed $value): static.

Example:

<?php

use Nelexa\Enum;

/**
 * @method static self PENDING()
 * @method static self ACTIVE()
 * @method static self INACTIVE()
 * @method static self DELETED()
 */
class UserStatus extends Enum
{
    public const
        PENDING = 1,
        ACTIVE = 1 << 1,
        INACTIVE = 1 << 2,
        DELETED = 1 << 3;
}

assert(UserStatus::fromValue(1 << 1) === UserStatus::valueOf('ACTIVE'));