geeksareforlife/config 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

geeksareforlife/config

Composer 安装命令:

composer require geeksareforlife/config

包简介

A simple configuration library

README 文档

README

A simple configuration library

This library stores config in two files - a normal config file and a defaults file.

When retrieving a value from the config, the normal config is checked first and if nothing is found the value from the defaults file is used.

Getting Started

Install Composer and run the following command to get the latest version:

composer require "geeksareforlife/config:^0.1"

Basic Usage

First, create a config object and load the files (Files will be created if they don't exist):

$config = new Config();
$config->load('/path/to/config.json', '/path/to/defaultConfig.json');

Then you can get or set values into the config object. Keys are dot-seperated.

$value = $config->getValue('key.name');
$config->setValue('key.name', $value);

When you have finished, you need to call the save function to commit the config to disk.

$config->save();

More Details

Values can be stored in two config files. Each file is a single JSON object.

Keys are in dot-notation, and an optional "module" can be used for each key. This allows you to have identical keys for different areas of your system.

Loading your config files

Once you have created the config object, you need to load the two config files. The config file needs to be writable, and both files will be created if they don't exist.

Getting a value

The getValue function returns the value of a given key:

getValue(string $key, [string $module]);

If the key is found in the config file, the value from there is returned. If not, the default file is checked and a value returned from there if available.

If the key is not found in either file, the function will return false

Setting a value

the setValue function behaves very similarly to the getValue

setValue(string $key, mixed $value, [string $module]);

The value is only ever stored in the config - the defaults are never touched.

At this point, the file itself it not saved, the value is only stored in-memory.

Saving the config

The save function saves the in-memory config to the config file.

统计信息

  • 总下载量: 17
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-09-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固