rnr1721/le7-config
Composer 安装命令:
composer require rnr1721/le7-config
包简介
Lightwaight PHP framework with API,CLI,WEB controllers - config classes
README 文档
README
Requirements
- PHP 8.1 or higher.
- Composer 2.0 or higher.
What it can?
- Read PHP (array), INI, and JSON files as config
- Load folder with config files to one (it understand config in all supported formats)
- Get config params as object properties
- Get config params as array values
- Get config params by path
- Strictly control param type and get default value if param not exists in config
- Use PSR SimpleCache interface for caching
- Get filtered params (with replacing parts of param values)
- You can write own adapter for your config types
- Register dynamic runtime parameter by path
Installation
composer require rnr1721/le7-config
Testing
composer test
How it works?
use Core\Config\ConfigFactoryGeneric; $data = [ 'myparam' => 2, 'myparam2' => "string value", 'myparam3' => [ 'myparam4' => false, 'myparam5' => 44.33 ] ]; $factory = new ConfigFactoryGeneric(); $config = $factory->fromArray($data); // Get params as object properties (null if empty) echo $config->myparam; echo $config->myparam3->myparam5; // Get params as array echo $config['myparam']; echo $config['myparam3']['myparam5']; // Get params by path (recommended way) echo $config->int('myparam',54); // 54 is default value if not exists in config echo $config->float('myparam3.myparam5',33.44); // 33.44 is default value if not exists in config echo $config->float('myparam3.myparam5'); // throw exception if value not exists in config var_dump($config->bool('myparam4/myparam4',true,'/')); echo $config->string('myparam2',"default value");
How load PHP array, JSON or INI file?
use Core\Config\ConfigFactoryGeneric; $filename = '/var/www/example.com/htdocs/config/config.php'; $factory = new ConfigFactoryGeneric(); $config = $factory->fromJsonFile($filename, 'My JSON config'); // echo $config['myparam']...
How load folder in different folders?
This config manager can load config from folder, in different formats. For example You have folder where placed JSON files, INI and php Arrays in files
use Core\Config\ConfigFactoryGeneric; $folders = [ '/var/www/example.com/htdocs/config', '/var/www/example.com/htdocs/config2' ]; $factory = new ConfigFactoryGeneric(); // $folders can be string - one folder or array // seconf parameter - is suffix between filename and extension i.e. dbConfig.ini or dbConfig.php in this case $config = $factory->harvest($folders, 'Config'); // $config->string('myparam')
How use cache?
Simply inject PSR CacheInterface/
use Core\Config\ConfigFactoryGeneric; $filename = '/var/www/example.com/htdocs/config/config.php'; // $cache is PSR Cacheinterface $factory = new ConfigFactoryGeneric($cache); // myconfig is cache key to store in cache $config = $factory->fromArrayFile($filename, 'My PHP config', 'myconfig'); // $config->string('myparam')
Filtered params
use Core\Config\ConfigFactoryGeneric; $data = [ 'myparam' => 2, 'myparam2' => "My site is {myvariable1}", 'myparam3' => [ 'myparam4' => false, 'myparam5' => 44.33 ] ]; $factory = new ConfigFactoryGeneric(); $config = $factory->fromArray($data); $config->applyFilter('vyvariable1','https://example.com'); // stringf will return "My site is https://example.com" echo $config->stringf('myparam2');
Dynamic parameters
You can add your own parameter (duplicates not allowed)
use Core\Config\ConfigFactoryGeneric; $data = [ 'myparam' => 2, 'myparam2' => "My site is {myvariable1}", 'myparam3' => [ 'myparam4' => false, 'myparam5' => 44.33 ] ]; $factory = new ConfigFactoryGeneric(); $config = $factory->fromArray($data); // Add own parameter $config->registerParam('myparam3.testparam77',"test value"); // Get this parameter $config->string("myparam3.testparam77");
Also you can combine dynamic parameters with filters:
use Core\Config\ConfigFactoryGeneric; $data = [ 'myparam' => 2, 'myparam2' => "My site is {myvariable1}", 'myparam3' => [ 'myparam4' => false, 'myparam5' => 44.33 ] ]; $factory = new ConfigFactoryGeneric(); $config = $factory->fromArray($data); // Add own parameter 1 $config->registerParam('myparam3.testdirhome',"/home/www",'homepath'); // Add own parameter 2 $config->registerParam('myparam3.testdirbase',"{homepath}/base"); // Get this parameter (return /home/www/base) $config->stringf("myparam3.testdirbase");
rnr1721/le7-config 适用场景与选型建议
rnr1721/le7-config 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 100 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 03 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「config」 「component」 「le7」 「le7-framework」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rnr1721/le7-config 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rnr1721/le7-config 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rnr1721/le7-config 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
FSi DataSource Component
A Zend Framework module to quickly and easily set PHP settings.
Priveate for SkeekS CMS
Server environment detection based on config array-file
Module for bootstrapping components in the Monolith framework.
统计信息
- 总下载量: 100
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-20