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

    }

使用之前引入我们所定义的类

 

二,测试效果:

 

posted @ 2025-02-09 19:18  刘宏缔的架构森林  阅读(51)  评论(0)    收藏  举报