gacela-project/gacela-yaml-config-reader

将yaml/yml文件加载到Gacela

dev-main 2023-05-14 11:22 UTC

This package is auto-updated.

Last update: 2024-09-14 14:26:23 UTC


README

为您的Gacela项目加载yaml/yml配置文件。

composer require gacela-project/gacela-yaml-config-reader

设置

您可以在Gacela::bootstrap()gacela.php文件中定义读取器配置。

选项A)

在项目的根目录中创建一个gacela.php文件来定义配置(推荐方式)

<?php # gacela.php

use Gacela\Framework\Bootstrap\GacelaConfig;
use Gacela\Framework\Config\ConfigReader\YamlConfigReader;

return static function (GacelaConfig $config): void {
    $config->addAppConfig('config/*.{yaml,yml}', 'config/local.yaml', YamlConfigReader::class);
};

选项B)

在引导程序中动态定义所有配置。

<?php  # public/index.php

use Gacela\Framework\Bootstrap\GacelaConfig;
use Gacela\Framework\Config\ConfigReader\YamlConfigReader;
use Gacela\Framework\Gacela;

$config = static function (GacelaConfig $config): void {
    $config->addAppConfig('config/*.{yaml,yml}', 'config/local.yaml', YamlConfigReader::class);
};

Gacela::bootstrap($appRootDir, $config);

您可以一次性定义多个ConfigReader

$config = static function (GacelaConfig $config): void {
    $config->addAppConfig('config/*.{yaml,yml}', 'config/local.yaml', YamlConfigReader::class);
    $config->addAppConfig('config/*.php', 'config/local.php');
    $config->addAppConfig('config/*.custom', '', CustomConfigReader::class);
}