gacela-project / gacela-yaml-config-reader
将yaml/yml文件加载到Gacela
dev-main
2023-05-14 11:22 UTC
Requires
- php: ^8.0, <8.3
- gacela-project/gacela: *
- symfony/yaml: ^5.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.13
- infection/infection: ^0.26
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^9.5
- psalm/plugin-phpunit: ^0.18
- symfony/var-dumper: ^5.4
- vimeo/psalm: ^5.1
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); }