hyperf: 定义常量
一,代码
1,定义常量的类
Constants/BusinessConstants.php
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace App\Constants;
use Hyperf\Constants\AbstractConstants;
use Hyperf\Constants\Annotation\Constants;
#[Constants]
class BusinessConstants extends AbstractConstants
{
//以下为图片业务自定义常量
public const IMAGE_WATER_SIGN = "软件水印";
}
2,调用常量
use App\Constants\BusinessConstants;
public function imagedetail(RequestInterface $request, ResponseInterface $response) {
$data = [
'water' => BusinessConstants::IMAGE_WATER_SIGN,
];
return $response->json($data);
}
使用之前引入我们所定义的类
二,测试效果:

浙公网安备 33010602011771号