andym84/config
Composer 安装命令:
composer require andym84/config
包简介
Configuration Management
README 文档
README
A simple (but effective!) system for managing different versions of configuration files and their settings.
Development Setup
There are no dependencies other than PHP (of course) to use the system, however if you'd like to use the source code and run the tests, feel free to clone or download the repo and run the following commands from the repository root:
composer update vendor/bin/phpunit -c phpunit.xml ./Tests
Installation
As with most things, I've made this available via Composer, you can add "andym84/config": "^1.0" to your composer.json or you can simply execute the command:
composer require andym84/config
Alternatively, of course, you're welcome to simply download the source code and reference it manually.
Usage
Usage of the system requires at least two things:
- A script that executes the
Migrator - A folder that contains one or more instruction files
Assuming you'll use a directory called cfgMigrations for your instruction files, your usage may be as simple
as this:
require('vendor/autoload.php'); use AndyM84\Config\ConfigContainer; use AndyM84\Config\Migrator; // Perform any required migrations $migrator = new Migrator('cfgMigrations'); $migrator->migrate(); // Consume the config file for easy use $cfg = new ConfigContainer(file_get_contents('siteSettings.json')); echo($cfg->get('configVersion')); // Echos whatever version your configs are at after migration
Consider the following two instruction files in your cfgMigrations directory, 0-1.cfg and 1-2.cfg.
cfgMigrations/0-1.cfg
siteVersion[str] + 1.0.0
siteTitle[str] + Default Title
cfgMigrations/1-2.cfg
siteTitle > frontTitle
backTitle[str] + Default Backend Title
smtp.host[str] + localhost
smtp.port[int] + 25
corsOrigins[str[]] + http://localhost
corsOrigins[str[]] + https://mydomain.com
If you run these through a migration, the system will produce the following siteSettings.json file:
{
"schema": {
"configVersion": "int",
"siteVersion": "str",
"frontTitle": "str",
"backTitle": "str",
"smtp.host": "str",
"smtp.port": "int",
"corsOrigins": "str[]"
},
"settings": {
"configVersion": 2,
"siteVersion": "1.0.0",
"frontTitle": "Default Title",
"backTitle": "Default Backend Title",
"smtp": {
"host": "localhost",
"port": 25
},
"corsOrigins": [
"http://localhost",
"https://mydomain.com"
]
}
}
Config Migrations
Each config migration is a file with simple per-line instructions. The file name is in the format <VERSION1>-<VERSION2>.cfg,
which allows the system to know which version it should look to migrate from and to. Instructions contain 2-3 segments:
<field-name-and-type> <operator>[ <value>]
The first two segments are required, and the third (value) is optional depending on the operator being used.
The following operators are available:
+ Add field w/ value
> Rename field
= Change field value
- Remove field
Valid field types:
int Integer
flt Float
str String
bln Boolean
int[] Array of Integers
flt[] Array of Floats
str[] Array of Strings
bln[] Array of Booleans
The array types can be added, renamed, or removed from migration files, but cannot be changed.
Finally, when used, the value segment can contain any character (excluding the newline), as well as these special
values:
"" Empty string
${propName} Interpolates the value of an existing property (will not be replaced if the property doesn't exist)
Finally, an example migration script, 3-4.cfg, which migrates the config file from version 3 to 4:
someVersion[str] + 1.1.2
ownerName[str] + Andrew Male
ownerFirstName -
ownerLastName > ownerSurname
This file will perform the following actions, in order:
- Add
someVersionstring property with value1.1.2 - Add
ownerNamestring property with valueAndrew Male - Remove
ownerFirstNameproperty - Rename
ownerLastNameproperty toownerSurname - Set
configVersioninteger property to4based on the file name
andym84/config 适用场景与选型建议
andym84/config 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.89k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 10 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「configuration」 「config」 「automation」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 andym84/config 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 andym84/config 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 andym84/config 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Configuration component
A Zend Framework module to quickly and easily set PHP settings.
Command-line utility for Vtiger CRM.
Historical accounting for contacts
Utils to load, parse and work with configuration on Mezzio projects
Extends Mautic Lead Bundle's Lead List (Segment) functionality.
统计信息
- 总下载量: 2.89k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-10-12