xervice/config

配置环境以适应xervice组件

3.1.0 2018-08-20 10:24 UTC

This package is auto-updated.

Last update: 2024-09-29 04:31:29 UTC


README

Scrutinizer Code Quality Code Coverage Build Status

Xervice服务的配置加载器。

安装

composer require xervice/config

配置

  1. 将配置目录添加到您的根路径
  2. 其中包含以下顺序解析的不同配置文件
    • config_default.php
    • config_.php
    • config__.php
    • config_local.php
    • (在之前的配置文件中定义的附加配置文件)

APPLICATION_ENV是一个环境变量。默认值是"production"。APPLICATION_SCOPE是一个环境变量。默认值是"main"。

要添加附加配置文件,可以将它们添加到config_default中

$config[\Xervice\Config\XerviceConfig::ADDITIONAL_CONFIG_FILES] = [
    __DIR__ . '/addition_config.php'
];

如果您想更改配置目录,可以设置环境变量CONFIG_PATH。如果没有定义CONFIG_PATH,它将在环境变量/config下查找。如果没有定义APPLICATION_PATH,它将在当前工作目录中查找。

用法

$configProvider = new XerviceConfig(new XerviceConfigFactory());
$config = $configProvider->getConfig();

$value = $config->get('CONFIG_KEY');

$valueWithDefault = $config->get('CONFIG_KEY', 'defaultvalue');


// Or with the static method way
$configProvider = XerviceConfig::getInstance();
$config = $configProvider->getConfig();

...

// Or direct static access
XerviceConfig::set('key', 'value');
XerviceConfig::get('key'); // value