当前位置: 首页 > article >正文

7. 配置

三种获取配置的方法

返回 /config/config.php 、/config/autoload/xxx.php 中的值

<?php
namespace App\Controller;

use Hyperf\Config\Annotation\Value;
use Hyperf\Contract\ConfigInterface;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\AutoController;
use function Hyperf\Config\config;

#[AutoController]
class ConfigController
{
  	// 1. 通过 注入 Hyperf\Contract\ConfigInterface 接口类来获取
    #[Inject]
    private ConfigInterface $config;

    // 2. 通过使用 Value 注解注入 对应配置项
    #[Value('foo.bar')]
    private $bar;

    public function index()
    {
        return $this->config->get('foo.bar');
    }
  
    public function value()
    {
        return $this->bar;
    }
  
    // 3. 通过 Config 全局函数
    public function config()
    {
      return config('foo.bar', 123);
    }
}

http://www.kler.cn/news/366472.html

相关文章:

  • Flutter之build 方法详解
  • 【Ubuntu】Virtualbox下lamp集群分布式搭建Wordpress
  • Java.6--多态-设计模式-抽象父类-抽象方法
  • 海港[NOIP2016]
  • vue-vant框架引入
  • Aloudata BIG 主动元数据平台支持 Oracle/DB2 存储过程算子级血缘解析
  • 用更多的钱买电脑而不是手机
  • 【pytest学习】pytest.main()
  • 数据库的CURD【MySql】
  • HttpContext模块 --- http上下文模块
  • 从零学习大模型(五)-----提示学习(Prompt Engineering)
  • 【C++融会贯通】多态
  • python爬虫实战案例——抓取B站视频,不同清晰度抓取,实现音视频合并,超详细!(内含完整代码)
  • 功能自动化测试工具Appium使用步骤讲解
  • 分类预测 | WOA-LightGBM基于鲸鱼算法优化轻量级梯度提升机算法数据分类预测Matlab程序
  • 安装OpenResty
  • Page Cache(页缓存)与脏页的关系
  • 安卓设备获取唯一id解决方案
  • rust:特征特征对象对象安全
  • 【JAVA毕业设计】基于Vue和SpringBoot的校园管理系统
  • Elasticsearch安装使用
  • Java线程死锁与活锁
  • Vue Router 如何配置 404 页面?
  • 解释 RESTful API,以及如何使用它构建 web 应用程序(AI)
  • 京准电钟:NTP网络校时服务器应用计算机大数据
  • 机器学习快速入门之手写体数字识别