PHP code example of gzoran / constant

1. Go to this page and download the library: Download gzoran/constant library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gzoran / constant example snippets


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;
}