jamesgober/config
Composer 安装命令:
composer require jamesgober/config
包简介
Advanced PHP configuration management designed for flexibility and performance, with built-in support for JSON, YAML, XML, INI, and limitless custom formats.
关键字:
README 文档
README
CONFIG MANAGER
BY JAMES GOBER
A Flexible PHP Configuration Manager
Config is a lightweight yet powerful PHP library designed to handle your application's configuration needs with ease and efficiency. Supporting multiple formats like JSON, XML, YAML, INI, and PHP arrays out of the box, it provides the flexibility to add custom parsers tailored to your specific requirements. With robust error handling, performance-focused design, and a modular architecture, JG\Config simplifies configuration management for modern PHP projects.
Key Features
- Multi-Format Support: Seamlessly load configurations from JSON, XML, YAML, INI, PHP, and CONF files.
- Custom Parsers: Extend functionality by adding support for any file format with ease.
- Performance Optimizations: Designed for speed, even with large or deeply nested configurations.
- Advanced Features: Includes caching, dynamic flattening control, and stream parsing for modern workflows.
- Robust Error Handling: Custom exceptions provide clear and actionable feedback for debugging.
- Lightweight and Intuitive: A simple yet powerful API designed for minimal overhead and ease of use.
Why Choose This Library?
JG\Config is built for developers who demand efficiency, reliability, and flexibility in their projects:
- High Performance: Optimized for speed with low overhead, making it ideal for high-load scenarios.
- Modular Design: Extend or replace parsers effortlessly to meet custom needs.
- Error-Resilient: Provides comprehensive error handling with meaningful exception messages.
- Extensively Tested: Rigorously tested with PHPUnit for predictable and stable performance.
- Built on Principles: Adheres to S.O.L.I.D design principles and emphasizes maintainability and extensibility.
Whether you're building a small application or managing a large-scale project, JG\Config provides a robust solution to streamline your configuration management.
Installation
Install via composer:
$ composer require jamesgober/config
Quick Start
Load Configurations
Effortlessly load multiple configuration files in various formats:
use JG\Config\Config; $config = new Config('/path/to/config/files'); // Load files $config->load('database.json'); $config->load('app.xml'); // Access values $dbHost = $config->get('database.host', 'default_host'); // Check keys if ($config->has('app.debug')) { echo "Debug mode is enabled!"; } // Add or update values $config->add('app.name', 'MyApp');
Manage Configurations
Easily delete individual values or entire groups:
// Delete specific values $config->delete('app.version'); // Removes app.version // Delete groups $config->delete('app'); // Removes app.name, app.debug, etc.
Extend with Custom Parsers
Add support for new file formats via custom parsers:
use JG\Config\ConfigParserFactory; // Register a parser for .custom files ConfigParserFactory::registerParser('custom', MyCustomParser::class);
Supported Formats
| Format | Example | Extension |
|---|---|---|
| CONF | config.conf |
.conf |
| INI | config.ini |
.ini |
| JSON | config.json |
.json |
| PHP Array | config.php |
.php |
| XML | config.xml |
.xml |
| YAML | config.yaml |
.yaml, .yml |
For more examples, see our Advanced Usage guide.
Error Handling
Custom Exceptions
JG\Config uses custom exceptions for intuitive error handling:
| Exception | Description |
|---|---|
ConfigException |
General errors related to configuration. |
ConfigParseException |
Errors when parsing configuration files. |
InvalidParserException |
When unsupported or invalid parsers are used. |
Example Usage:
use JG\Config\Exceptions\ConfigException; try { $config->load('missing_file.json'); } catch (ConfigException $e) { echo "Error: " . $e->getMessage(); }
Advanced Features
Explore advanced capabilities like caching, custom parsers, and dynamic flattening in our Advanced Guide.
Directory Structure
src/
├── Config.php # Core configuration management class
├── ConfigParserFactory.php # Factory for parser resolution
├── Exceptions/ # Custom exceptions for robust error handling
│ ├── ConfigException.php
│ ├── ConfigParseException.php
│ └── InvalidParserException.php
├── Parsers/ # Built-in parsers for supported formats
│ ├── ParserInterface.php
│ ├── PhpParser.php
│ ├── JsonParser.php
│ ├── IniParser.php
│ ├── XmlParser.php
│ └── YamlParser.php
tests/ # Unit and integration tests
Reporting Security Issues
We take security seriously. If you find a vulnerability, please consult our SECURITY POLICY and follow the instructions for reporting.
Do not use public issue trackers or forums to disclose sensitive information.
Reporting Bugs and Feature Requests
For non-security issues, such as bugs or feature requests, please use our Issue Tracker. Providing detailed information will help us resolve issues efficiently.
Design Philosophy
Learn about the principles that guide the development of JG\Config in our Design Philosophy.
Contributing
Contributions are welcome! Check out the Contribution Guidelines and review our Code of Conduct for more information.
License
This library is open-source software licensed under the MIT license.
↑
TOP
COPYRIGHT © 2024 JAMES GOBER & JAMESGOBER.COM.
jamesgober/config 适用场景与选型建议
jamesgober/config 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 51 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 11 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「yaml」 「php」 「json」 「xml」 「configuration」 「parser」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jamesgober/config 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jamesgober/config 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jamesgober/config 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kinikit - PHP Application development framework MVC component
ext-json wrapper with sane defaults
A package to cast json fields, each sub-keys is castable
SUML for PHP
SUML support for Symfony
provides an facade for php-yaml, syck and symphony/yaml so switching in between is easier
统计信息
- 总下载量: 51
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-11-22