Hyperf
的配置文件全部存放在 config\config.php
、和 config\autoload
文件夹
config.php 与 autoload 文件夹内的配置文件的关系
config.php
与autoload
文件夹内的配置文件在服务启动时都会被扫描并注入到Hyperf\Contract\ConfigInterface
对应的对象中,配置的结构为一个键值对的大数组,两种配置形式不同的在于autoload
内配置文件的文件名会作为第一层 键(Key) 存在,而config.php
内的则以您定义的为第一层
获取配置
通过依赖注入获取配置
<?php
declare(strict_types=1);
namespace App\Controller;
use Hyperf\Contract\ConfigInterface;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Contract\ResponseInterface;
/**
* @Controller()
* Class AuthController
* @package App\Controller
*/
class AuthController
{
/**
* @Injec