nitier/config-loader
最新稳定版本:0.9.9
Composer 安装命令:
composer require nitier/config-loader
包简介
README 文档
README
A flexible configuration loader for PHP projects with support for multiple formats and easy extensibility.
📦 Installation
composer require nitier/config-loader
🌟 Features
- Supports multiple formats:
.php,.json,.env - Deep configuration merging
- Easy integration of custom loaders
- Automatic type conversion for
.envfiles - PSR-4 compatible
🚀 Quick Start
Basic Usage
use Nitier\ConfigLoader\Config; // Load a single configuration file $config = Config::load('/path/to/config.php'); // Load multiple files with overrides $config = Config::load([ '/path/to/base.json', '/path/to/override.env' ]);
Example .env File
APP_DEBUG=true DB_HOST=localhost DB_PORT=3306
🔌 Available Loaders
| Format | Class | Supported Extensions |
|---|---|---|
| PHP | PhpLoader |
.php, .inc |
| JSON | JsonLoader |
.json |
| ENV | EnvLoader |
.env |
🛠 Extending Functionality
Adding a Custom Loader
- Create a class implementing
LoaderInterface:
namespace App\ConfigLoaders; use Nitier\ConfigLoader\Interface\LoaderInterface; class XmlLoader implements LoaderInterface { public static function supports(string $extension): bool { return $extension === 'xml'; } public static function load(string $path): array { // Your XML parsing implementation here } }
- Register the loader:
Config::addLoader(\App\ConfigLoaders\XmlLoader::class);
⚙️ Configuration
Loader Priorities
Loaders are checked in the order they were registered. The most recently added loaders take priority.
Deep Merging
When loading multiple configuration files, arrays are merged recursively:
// base.php ['db' => ['host' => 'localhost', 'user'=> 'test']] // override.php ['db' => ['user'=> 'prod', 'port' => 3306]] // Result ['db' => ['host' => 'localhost', 'user'=> 'prod', 'port' => 3306]]
📜 License
MIT
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2025-03-24