xianyu/enum

Maintainers

Details

github.com/qinshuze/enum

Source

Issues

Installs: 9

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/xianyu/enum

v1.0.0 2020-06-20 08:35 UTC

This package is auto-updated.

Last update: 2025-12-20 21:18:50 UTC


README

php枚举

使用方法

Test.php

/**
 * Class StatusEnum
 * @method static self OK
 * @method static self LOCK
 */
class StatusEnum extends \Xianyu\Enum\Enum
{
    private const OK   = [1, '正常'];
    private const LOCK = [2, '锁定'];

    /** @var string */
    private $key;
    /** @var string */
    private $value;

    /**
     * StatusEnum constructor.
     * @param string $key
     * @param string $value
     */
    public function __construct(string $key, string $value)
    {
        $this->key = $key;
        $this->value = $value;
    }

    /**
     * @return string
     */
    public function getKey(): string
    {
        return $this->key;
    }

    /**
     * @return string
     */
    public function getValue(): string
    {
        return $this->value;
    }
}

echo StatusEnum::OK()->getKey();    // 1
echo StatusEnum::OK()->getValue();  // 正常