PHP code example of mr-litt / create_errors_code

1. Go to this page and download the library: Download mr-litt/create_errors_code 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/ */

    

mr-litt / create_errors_code example snippets




namespace app\helpful;

class ErrorCode
{
    const MY_DEFINE_ERROR = 403;    //自己定义的错误码
}



namespace app\service;
use app\helpful\ErrorCode;

class SiteService
{
    public function index(){
        $existError = true;
        if($existError){
            echo ErrorCode::ERROR_DEMO1;    //错误标识1
            echo ErrorCode::ERROR_DEMO2;    //错误标识2
        }
    }
}



use app\helpful\ErrorCode;
use create_code\CreateErrorsCode;

$option = [
    "target"=>new ErrorCode(),  //错误文件类
    "root"=>__DIR__,    //项目根目录
    "min"=>10000,    //选填,生成错误码基数,默认10000
];

(new CreateErrorsCode($option))->run();

    app //你的应用目录
        -helpful
            -ErrorCode.php  //生成你的错误类文件
            ...
        -service
            -SiteSerive.php //在你项目里使用定义错误标识
            ...
        index.php   //使用CreateErrorsCode类生成错误码