tinyapps / yaml-config
用于使用yaml配置文件的简单PHP库
v1.3.0
2022-05-15 15:32 UTC
Requires
- php: ^8.0
- symfony/yaml: ^6.0
Requires (Dev)
- phpunit/phpunit: ^9.5
README
YAML配置
一个简单的PHP库,方便使用yaml配置文件并将(可选的)它们加载到环境变量中。
要求
PHP ^8.0 或 ^8.1 以及php-yaml扩展(v1.2.0基于symfony/yaml)
您可以使用v1.0.2或更低版本与PHP 7.4兼容(但需要php-yaml扩展)。
安装
composer require tinyapps/yaml-config
使用
配置
$config = new \TinyApps\YamlConfig\Config(__DIR__ . '/config.yml'); var_dump($config->get('your_variable')); // or var_dump($config['your_variable']); // or var_dump($config->your_variable); // You can also set the config directory once for easier access \TinyApps\YamlConfig\Config::setConfigDir(__DIR__ . '/example-configs'); $config = new Config('example'); // will read example-configs/example.yml $config = new Config('sub/test'); // will read example-configs/sub/test.yml
将配置加载到环境变量中
TinyApps\YamlConfig\EnvLoader::init(__DIR__ . '/env.yml'); var_dump(getenv('your_environment_variable'));
从配置中获取单个值(静态上下文)
TinyApps\YamlConfig\Config::getConfigValue('example', 'property'); // returns the "property" value from example config