amanangira/php-config-manager

该库允许开发者实现基于文件的配置的不同格式。

v1.3 2019-03-28 09:48 UTC

This package is auto-updated.

Last update: 2024-09-28 01:18:09 UTC


README

该库允许开发者以简单、有序和语法友好的方式使用基于文件的配置。该库的设计理念是方便开发者并减少工作量。目前它支持两种类型,即JSON和PHP数组。基础类很容易扩展以支持更多文件类型。

安装

Composer

composer require amanangira/php-config-manager

Git

git clone https://github.com/amanangira/php-config-manager.git

使用

初始化

基于PHP数组的配置管理器

use AmanAngira\ConfigManager\PhpArray\Manager;

$path = __DIR__ . '/config'; //Directory where the library expects the configuration files
$manager = new Manager($path); //Initializing object with the configurations path

基于JSON的配置管理器

use AmanAngira\ConfigManager\Json\Manager;

$path = __DIR__ . '/config'; //Directory where the library expects the configuration files
$manager = new Manager($path); //Initializing object with the configurations path

访问配置值

$value = $manager->get('foo.var'); //use file name only (without extension) followed by full stop to access child values
if( $value === Manager::NOT_FOUND_FLAG ) //library flag if a value is not defined 
  echo "Value not defined";
else
  echo $value;

待办事项

  • 实现基于缓存的配置
  • 启用在当前请求范围内修改配置值