一 常量(常量和对应的msg)
declare(strict_types=1);
namespace App\Constants;
use Hyperf\Constants\AbstractConstants;
use Hyperf\Constants\Annotation\Constants;
#[Constants]
class ErrorCode extends AbstractConstants
{
const SERVER_ERROR = 500;
const SYSTEM_INVALID = 700;
}
echo ErrorCode::SYSTEM_INVALID;
echo ErrorCode::getMessage(ErrorCode::SERVER_ERROR);
二 取配置数据
//配置于config.php
$config = [
'app_name' => config("app_name"),
'demo_a' => config('config_demo.a'), //二级
'demo_c' => config('config_demo.b.c'), //3级
];
#使用注解
use Hyperf\Config\Annotation\Value;
#[Value("app_env")]
private $appEnv;
echo $this->appEnv;

三 取不同配置文件的配置数据
'redis' => config('redis')['default']['host']
四 小套路,不存在且取默认值
$env = env("a", 1);
$config = config("b",2);