corneltek/configkit
Composer 安装命令:
composer require corneltek/configkit
包简介
Fast config toolkit, which provides super lightweight config accessor and loader.
README 文档
README
ConfigKit compiles your readable YAML config file to PHP files automatically.
YAML format is clean, smart, easy. but in PHP, you have to parse yaml config file in every request. Parsing YAML costs too much CPU time. How to improve it ?
php-ConfigKit is a library for config files and which is designed for performance, it parses yaml config files for the first time, then compiles the config files into php files, so these config files can be cached in PHP, and it can also be in APC or any other cache backend system.
ConfigKit is simple and fast, all you have to do is defining your config file in YAML format, then use ConfigKit to load the config file.
ConfigKit uses static methods because static methods are faster than object methods.
It checks if a {config file}.php exists, if so, then checks the file
modification time to decide whether to recompile yaml files.
When APC extension is enabled, PHP source code can be cached in APC, so when you require the pure php source file, it will be faster then reparsing it from yaml.
A generated config PHP file is like:
<?php return array ( 'ApplicationName' => 'Phifty', 'ApplicationID' => 'phifty', 'ApplicationUUID' => '9fc933c0-70f9-11e1-9095-3c07541dfc0c', 'Domain' => 'phifty.dev',
Requirement
YAML extension
Installation
Composer:
{
"require": {
"corneltek/configkit": "~1.5"
}
}
Usage
ConfigCompiler
To compile a yaml config file and get the config stash:
$config = ConfigCompiler::load('tests/ConfigKit/data/framework.yml'); print_r( $config );
To disable stats check (mtime checking):
ConfigCompiler::$statCheck = false; $config = ConfigCompiler::load('tests/ConfigKit/data/framework.yml');
If you want to compile the config file manually, you may call the compile static function to do that:
$compiledFile = ConfigCompiler::compile('config/framework.yml');
You may also specify the compiled filename in the arguments:
$compiledFile = ConfigCompiler::compile('config/framework.yml', 'config/framework.php');
You can also override some config values during the compilation, by using the override_compile function:
$compiledFile = ConfigCompiler::override_compile('config/framework.yml', array( 'something_should_not_be_in_config_file' => 123123123, 'something_should_not_be_in_git' => 123123123, 'something_generated_in_the_runtime' => random(), ));
To test if a compiled file needs to be updated (re-compile):
if ( ConfigCompiler::test('config/framework.yml','config/framework.php')) ) { ConfigCompiler::compile(....); } else { // already up to date. }
ConfigLoader
You can manage multiple config files with ConfigLoader
$loader = new ConfigLoader; $loader->load( 'framework', 'config/framework.yml' ); $loader->load( 'database', 'config/database.yml' );
To get config stash
$paths = $loader->get('framework','web.paths'); $templates = $loader->get('framework','web.templates'); foreach( $paths as $path ) { echo $path, "\n"; }
To write all config stash into one cache file:
$loader->writeStashes('all.php');
To load all config stash back:
$loader->loadStashes('all.php');
Generate AppConfigLoader class
$loader = new ConfigKit\ConfigLoader; $loader->load('database','tests/data/database.yml'); $loader->load('framework','tests/data/framework.yml'); $appClass = $loader->generateAppClass('MyApp\\AppConfigLoader'); $path = $appClass->generatePsr4ClassUnder('tests'); require_once($path); $appConfigLoader = new \MyApp\AppConfigLoader;
corneltek/configkit 适用场景与选型建议
corneltek/configkit 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14.21k 次下载、GitHub Stars 达 13, 最近一次更新时间为 2013 年 03 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「yaml」 「cache」 「config」 「accessor」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 corneltek/configkit 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 corneltek/configkit 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 corneltek/configkit 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
A Zend Framework module to quickly and easily set PHP settings.
Laravel 5 - Repositories to the database layer
SUML for PHP
SUML support for Symfony
Server environment detection based on config array-file
统计信息
- 总下载量: 14.21k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 13
- 点击次数: 21
- 依赖项目数: 8
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-03-21