lengbin/hyperf-error-code

hyperf error code

dev-main 2020-10-30 17:05 UTC

This package is auto-updated.

Last update: 2024-10-15 12:48:04 UTC


README

Hyperf Error Code Command


If You Like This Please Give Me Star

Install

The preferred way to install this extension is through composer.

Either run

composer require lengbin/hyperf-error-code

or add

"lengbin/hyperf-error-code": "*"

to the require section of your composer.json file.

you can see document

Configs

    // 配置 /config/autoload/errorCode.php
    return [
        // 错误码文件 目录
        'path'           => [
            BASE_PATH . '/app/Constant/Errors'
        ],
        // 合并生成 类 文件名称
        'classname'      => 'Error',
        // 合并生成 类 命名空间
        'classNamespace' => 'App\\Constant',
        // 合并生成 类 文件输出目录
        'output'         => BASE_PATH . '/app/Constant',
    ];



class ErrorCode extends BaseEnum
{
    /**
     * @Message("成功")
     */
    const SUCCESS = '0';
}

$error = ErrorCode::byValue(ErrorCode::SUCCESS);

$error->getName();  // SUCCESS
// 支持多语言
$error->getMessage([], 'zh-CN'); // 成功
$error->getValue(); // 0

Publish

php ./bin/hyperf.php vendor:publish lengbin/hyperf-error-code

Usage

php ./bin/hyperf.php gen:error-code