devuri/config

为PHP应用程序提供轻量级配置管理库。

v0.1.5 2024-05-03 03:33 UTC

This package is auto-updated.

Last update: 2024-09-19 20:55:40 UTC


README

SimpleConfig是一个轻量级的PHP配置管理库,旨在提供一种简单灵活的方式来处理配置设置。它利用dflydev/dot-access-data,通过点表示法方便地访问嵌套配置值。

特性

  • 轻松加载和合并配置文件。
  • 特定环境的配置覆盖。
  • 简单的点表示法来访问嵌套配置值。
  • 可选的缓存机制以增强性能。

安装

使用Composer将SimpleConfig安装到项目中

composer require devuri/config

用法

基本用法

use Urisoft\SimpleConfig;

// Define your configuration path and allowed files
$configPath = __DIR__ . '/config';
$allowedFiles = ['app', 'database'];

// Instantiate the SimpleConfig object
$config = new SimpleConfig($configPath, $allowedFiles, 'production', 'path/to/configCache.php');

// Access configuration values
$appName = $config->get('app.name');
$dbHost = $config->get('database.connections.mysql.host');

设置配置值

// Set a new configuration value
$config->set('app.timezone', 'UTC');

// Retrieve the newly set value
echo $config->get('app.timezone'); // Outputs: UTC

清除缓存

// Manually clear the configuration cache
$config->clearCache();

贡献

请提交任何功能、修复或改进的pull请求或创建问题。

许可证

根据MIT许可证授权。有关详细信息,请参阅LICENSE文件。