kariricode/configurator
Composer 安装命令:
composer require kariricode/configurator
包简介
A flexible and efficient configuration management component for the KaririCode Framework, providing robust configuration handling for PHP applications.
关键字:
README 文档
README
A flexible and powerful configuration management component for the KaririCode Framework, providing robust configuration handling capabilities for PHP applications.
Features
- Support for multiple configuration file formats (PHP, JSON, YAML)
- Hierarchical configuration structure
- Easy access to configuration values
- Configuration validation
- Merge strategies for combining multiple configuration sources
- Extensible loader system for custom configuration sources
- Secure handling of sensitive configuration data
Installation
To install the KaririCode Configuration component, run the following command:
composer require kariricode/configuration
Basic Usage
Step 1: Setting Up Configuration Files
Create your configuration files in the supported formats (PHP, JSON, or YAML). For example:
// config/app.php <?php return [ 'name' => 'MyApp', 'version' => '1.0.0', 'debug' => true, ];
// config/database.json { "host": "localhost", "port": 3306, "username": "root", "password": "secret" }
# config/cache.yaml driver: redis host: localhost port: 6379
Step 2: Initializing the Configuration Manager
Set up the Configuration manager in your application's bootstrap file:
<?php require_once __DIR__ . '/../vendor/autoload.php'; use KaririCode\Configurator\Configuration; use KaririCode\Configurator\Loader\JsonLoader; use KaririCode\Configurator\Loader\PhpLoader; use KaririCode\Configurator\Loader\YamlLoader; $config = new Configuration(); $config->registerLoader(new PhpLoader()); $config->registerLoader(new JsonLoader()); $config->registerLoader(new YamlLoader()); // Load configuration files $config->load(__DIR__ . '/../config/app.php'); $config->load(__DIR__ . '/../config/database.json'); $config->load(__DIR__ . '/../config/cache.yaml');
Step 3: Accessing Configuration Values
Once the configuration is loaded, you can access values like this:
// Get a single configuration value $appName = $config->get('app.name'); $dbHost = $config->get('database.host'); $cacheDriver = $config->get('cache.driver'); // Check if a configuration key exists if ($config->has('app.debug')) { // Do something } // Get all configuration values $allConfig = $config->all();
Step 4: Using Environment-Specific Configuration
You can load environment-specific configuration files:
$environment = getenv('APP_ENV') ?: 'production'; $config->load(__DIR__ . "/../config/{$environment}/app.php");
Advanced Usage
Custom Loaders
You can create custom loaders for specific file types:
use KaririCode\Configurator\Contract\Configurator\Loader; class XmlLoader implements Loader { public function load(string $path): array { // Implementation for loading XML files } public function getTypes(): array { return ['xml']; } } $config->registerLoader(new XmlLoader());
Merge Strategies
The component supports different merge strategies for combining configurations:
use KaririCode\Configurator\MergeStrategy\StrictMerge; $config = new Configuration( mergeStrategy: new StrictMerge() );
Validation
The component includes automatic validation of configuration values:
use KaririCode\Configurator\Validator\AutoValidator; $config = new Configuration( validator: new AutoValidator() );
Testing
To run tests for the KaririCode Configuration Component, use PHPUnit:
make test
For test coverage:
make coverage
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support and Community
- Documentation: https://kariricode.org
- Issue Tracker: GitHub Issues
- Community: KaririCode Club Community
- Professional Support: For enterprise-level support, contact us at support@kariricode.org
Acknowledgments
- The KaririCode Framework team and contributors.
- The PHP community for their continuous support and inspiration.
Built with ❤️ by the KaririCode team. Empowering developers to build more robust and flexible PHP applications.
Maintained by Walmir Silva - walmir.silva@kariricode.org
kariricode/configurator 适用场景与选型建议
kariricode/configurator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 09 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「php」 「configuration」 「config」 「configurator」 「system configuration」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kariricode/configurator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kariricode/configurator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kariricode/configurator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
Configuration component
Utils to load, parse and work with configuration on Mezzio projects
Trait to support creating complex nested class structures from JSON/YAML objects.
Alfabank REST API integration
Advanced configuration manager for PHP with dotted-path access, file/directory/class loaders and a static facade.
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-28