apinstein/config_magic
Composer 安装命令:
composer require apinstein/config_magic
包简介
Configuration management system for arbitrary
关键字:
README 文档
README
A simple organizational tool to help you manage config files for your web app.
INSTALLATION
$ composer global require apinstein/config_magic
HOW IT WORKS
A typical web app has 1 or more config files. For instance, your app might have the following files: httpd.conf (apache config) webapp.conf (framework config) sh.conf (shell script config)
A typical web app is also run on more than one server. For instance: dev-alan dev-jason staging production
Configuring your web app to run on a new envirionment can quickly become a painful process as you have to remember to edit multiple files with correct information. In my experience, a lot of time is wasted trying to: - Bootstrap the new environment one config file at a time - Remember all of the different places and values that need to be configued - Messing with regex replacements to try to batch-replace things listed repetitively
ConfigMagic solves these problems by letting you quickly and easily set up template files for each config file. Your template file can contain default data for each variable substitution used by your configs. You then need only set up a profile.ini for each machine profile and declare any non-default data you need to use. ConfigMagic then writes out all config files for a given profile.
ConfigMagic comes with a command-line utility "cfg" that lets you quickly manage this process.
EXAMPLE
Initialize ConfigMagic for this project.
$ cfg -i
Set up an example config file
$ echo "myProfile = ##PROFILE##" > config/templates/example.conf $ echo "myVar = ##my.var##" >> config/templates/example.conf
Set up an empty profile
$ echo "my.var = 10" > config/profiles/dev.ini
Build all config files for the "dev" profile
$ cfg dev
Check
$ cat config/example.conf
Output:
myProfile = dev
myVar = 10
VARIABLE SUBSTITUION
Variables in the template files take the form of:
##my.var##
And will be replace by the corresponding ini file variable:
my.var
Variables in the profile.ini file override the default values set in the config.ini file.
Variables can also use variable substituion on variables previously defined (ie higher in the file).
a = foo b = ##a##-bar # b = foo-bar
The following additional variables are automatically defined:
##CONFIG## => the current config name
##PROFILE## => the current profile name
##CONFIG_DIR## => the absolute path to the config dir
##OUTPUT_DIR## => the absolute path to the output dir
##TEMPLATES_DIR## => the absolute path to the config/templates dir
Any variable substitution in the template file that isn't defined in any ini file will be skipped and a warning will print out.
DYNAMIC TEMPLATES
All templates are treated as PHP code, which means that you can use normal PHP syntax to dynamically generate config files based on profile data.
All variables available in normal variable substition (in form of ##varname##) are available in the template, via the $profileData variable. For instance:
<?php if (!$profileData['##isProduction##']): ?> 'classname' => 'DebugPDO', <?php endif; ?>
NOTE: if you are actually generating a php file, you will need to escape php tags so that they are not seen as a "PHP Start Tag":
long php tags
<<?php ?>?php
short php tags
<<? ?>?
DYNAMIC VARIABLES
In some cases you may want to programmatically munge the profile data directly rather than in the template files via dynamic templates.
A good example of this is to call realpath() on a path at the variable level so you don't have to remember to do this in each template.
This can be done with this simple syntax:
project.dir = "<?php realpath('##OUTPUT_DIR##/..') ?>"
The php processing will occur after the variable substitution has processed.
CONCLUSION
Getting started with ConfigMagic is very easy and provides a solid organizational framework to manage your config files. I hope you enjoy it.
Please feel free to send comments or suggestions my way.
apinstein/config_magic 适用场景与选型建议
apinstein/config_magic 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12.55k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2013 年 01 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「config」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 apinstein/config_magic 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 apinstein/config_magic 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 apinstein/config_magic 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Zend Framework module to quickly and easily set PHP settings.
Server environment detection based on config array-file
Single and multi-dimensional parameter bag with dot-path access for PHP.
Laravel provider to be able to rewrite configuration
Advanced configuration manager for PHP with dotted-path access, file/directory/class loaders and a static facade.
Config component from JiNexus Framework
统计信息
- 总下载量: 12.55k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-01-22