PHPackages                             gzoran/constant - 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. gzoran/constant

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

gzoran/constant
===============

常量类提供了一些对常量操作的基本方法

1.1.1(7y ago)1977MITPHP

Since Dec 4Pushed 7y agoCompare

[ Source](https://github.com/gzoran/constant)[ Packagist](https://packagist.org/packages/gzoran/constant)[ RSS](/packages/gzoran-constant/feed)WikiDiscussions master Synced 3d ago

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

Constant
========

[](#constant)

常量抽象类 ConstantAbstract 实现了 ConstantContract 契约，提供对常量便捷定义与访问等的操作

[![Build Status](https://camo.githubusercontent.com/f0b41ed99ab6345d2a9b02772b099cdb1d5c3d49040e9fe2a899287f196b1344/68747470733a2f2f7472617669732d63692e6f72672f677a6f72616e2f636f6e7374616e742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/gzoran/constant)[![StyleCI build status](https://camo.githubusercontent.com/59b7c5eaa8be0abef68b07d9f590c64eba4e46fba4ac2b2cc66ff0f5c87cb3dc/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3136303331313339302f736869656c64)](https://camo.githubusercontent.com/59b7c5eaa8be0abef68b07d9f590c64eba4e46fba4ac2b2cc66ff0f5c87cb3dc/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3136303331313339302f736869656c64)

安装
--

[](#安装)

```
composer require "gzoran/constant:~1.0"
```

使用
--

[](#使用)

现在我们建立一个 “游戏状态” 常量类 GameStatus。

```
class GameStatus extends ConstantAbstract
{
    /**
     * 定义常量 禁用
     *
     * @var int
     */
    const DISABLE = 0;

    /**
     * 定义常量 激活
     */
    const ACTIVE = 1;

    /**
     * 这里必须实现常量契约的 mapping 方法，用以配置 “常量” 与 “名称” 的对应关系
     *
     * @author Mike
     * @return array
     */
    public static function mapping()
    {
        return [
            self::DISABLE => '已禁用',
            self::ACTIVE  => '已激活'
        ];
    }
}
```

使用常量

```
// 如果游戏状态为激活，则返回 true
if ($status == GameStatus::ACTIVE) {
    return true;
}
```

获取常量名称

```
$status = 1;

// 获取状态为 1 的名称
$description = GameStatus::name($status);
```

检查常量是否配置

```
$status = 1;

// 如果状态 1 已配置，则返回 true

if (GameStatus::isExist($status)) {
    return true;
}
```

License
-------

[](#license)

MIT

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity64

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 ~56 days

Total

3

Last Release

2607d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d0ad4f92147e31cc7ad2b275c7e295cef20e5d08dc917bb997267f0d9ece3d50?d=identicon)[gzoran](/maintainers/gzoran)

---

Top Contributors

[![gzoran](https://avatars.githubusercontent.com/u/28888200?v=4)](https://github.com/gzoran "gzoran (9 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/gzoran-constant/health.svg)

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

PHPackages © 2026

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