danack/configurator
Composer 安装命令:
composer require danack/configurator
包简介
Generates config files from PHP, JSON and Yaml data files.
README 文档
README
A few simple tools to manage configuration data sanely. These tools are to hold environment data that can be shared without risk. They are not designed to hold 'secrets' e.g. api/oauth keys.
-
Config file generator
-
Environment settings generator
-
Convert PHP ini files to PHP-FPM format
Philosophy
Environment variables need to be granular controls. Although they can be grouped together as "environments", they need to be configurable on a per-deploy basis without duplicating large blocks of information.
They also need to be stored alongside the application's code so that they can be maintained easily.
This library allows you to do these two things. All environment settings can be stored in a simple way, and then extracted and combined with arbitrary combinations. E.g. using 'centos,dev' as the environment setting uses all the 'centos' environment settings, with the 'dev' settings over-riding any duplicate settings.
Example usage for people who don't like reading instructions
If you install Configurator through Composer, the executable files will be in the vendor/bin directory and can be run with:
# Generate nginx config file for the centos,dev environment vendor/bin/configurate -p example/config.php example/config_template/nginx.conf.php autogen/nginx.conf "centos,dev" # Generate a PHP file that contains a function which returns the current application env settings vendor/bin/genenv -p example/config.php example/envRequired.php autogen/appEnv.php "centos,dev" # Convert a PHP ini file to be in the PHP-FPM format vendor/bin/fpmconv autogen/php.ini autogen/php.fpm.ini
Config file generator
This tool allows you to generate config files from PHP based templates and PHP data files that hold all of the settings for the different environments.
Source config template file:
<?php $config = <<< END server { access_log ${'nginx.log.directory'}/project.access.log requestTime; error_log ${'nginx.log.directory'}/project.error.log; root ${'project.root.directory'}/public; } END; return $config;
Data file that holds data for arbitrary environments:
<?php $centos = [ 'nginx.log.directory' => '/var/log/nginx', 'project.root.directory' => '/home/project', ]; $windows = [ 'nginx.log.directory' => 'c:/nginx', 'project.root.directory' => 'c:/documents/project', ]; $john = [ 'project.root.directory' => '/home/workdir/project', ]
Running the command configurate data/nginx.conf.php var/generated/nginx.conf centos,john -p settings.php would generate the file:
access_log /var/log/nginx/project.access.log requestTime;
error_log /var/log/nginx/project.error.log;
root /home/workdir/project/public;
Syntax
configurate [-p|--phpsettings="..."] [-j|--jssettings="..."] input output environment
| -p | A comma separated list of PHP data files. Each need to return an array of data. |
| -j | A comma separated list of JSON data files. |
| -y | A comma separated list of YAML files. |
| input | The input template file. |
| output | The output file to write. |
| environment | A comma separated list of environment settings to apply. |
Generate environment settings
A tool that will parse the environment settings required by an application and the data files that hold the settings for all environments, and generate a file that contains a function which returns an array of what env settings are required by this application.
Given this file listing the environment settings required by an application:
<?php use ExampleApp\AppConfig; $env = [ AppConfig::CACHING_SETTING, AppConfig::SCRIPT_PACKING, AppConfig::FILE_STORAGE ]; return $env;
And a data file that holds all the data for the various environment settings:
$dev = [ AppConfig::SCRIPT_PACKING => true, AppConfig::CACHING_SETTING => 'caching.disable', ]; $live = [ AppConfig::SCRIPT_PACKING => true, AppConfig::CACHING_SETTING => 'caching.time' ]; // Anyone doing UX testing needs to have the scripts packed together // to avoid slow UI responses $uxtesting = [AppConfig::SCRIPT_PACKING => true];
Running the command bin/genenv -p environment/config.php environment/envRequired.php env.php dev,uxtesting produces a file containing a single function which contains all the requested env settings:
<?php function getAppEnv() { static $env = [ 'caching.setting' => 'caching.disable', 'script.packing' => 'true', ]; return $env; }
The keys are actual strings rather than the constants used in the application to allow the settings to be used outside of the application.
Syntax
genenv [-p|--phpsettings="..."] [-j|--jssettings="..."] input output environment
| -p | A comma separated list of PHP data files. Each need to return an array of data. |
| -j | A comma separated list of JSON data files. |
| -y | A comma separated list of YAML files. |
| input | The input template file. |
| output | The output file to write. |
| environment | A comma separated list of environment settings to apply. |
Convert PHP ini files to PHP-FPM format
Because of reasons, PHP-FPM doesn't use the standard PHP in file format when including ini files in a pool in the PHP-FPM conf file. This aspect of the Configurator converts PHP style ini files to the format PHP-FPM expects:
Input ini file:
extension=imagick.so
default_charset = "utf-8";
post_max_size = 10M
Running the command php bin/fpmconv example.php.ini example.phpfpm.ini
will generate this PHP-FPM ini file:
php_admin_value[extension] = "imagick.so"
php_admin_value[default_charset] = "utf-8"
php_admin_value[post_max_size] = "10M"
danack/configurator 适用场景与选型建议
danack/configurator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.92k 次下载、GitHub Stars 达 14, 最近一次更新时间为 2016 年 03 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「configuration」 「config」 「utf-8」 「tool」 「environment」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 danack/configurator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 danack/configurator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 danack/configurator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Configuration component
A Zend Framework module to quickly and easily set PHP settings.
Utils to load, parse and work with configuration on Mezzio projects
Server environment detection based on config array-file
Single and multi-dimensional parameter bag with dot-path access for PHP.
Trait to support creating complex nested class structures from JSON/YAML objects.
统计信息
- 总下载量: 9.92k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 3
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-03-18