lukman-ss/config
Composer 安装命令:
composer require lukman-ss/config
包简介
Standalone PHP configuration repository, env loader, file loader, and cache utility.
README 文档
README
Standalone PHP configuration library with a repository, typed getters, .env loading, PHP config file loading, cache files, and freeze mode.
Requirements
- PHP 8.2 or higher
- No runtime dependencies
Installation
composer require lukman-ss/config
Basic Usage
use Lukman\Config\Config; $config = new Config(); $config ->set('app.name', 'Demo') ->set('app.debug', true); $name = $config->string('app.name'); $debug = $config->bool('app.debug');
Repository
use Lukman\Config\Repository; $repository = new Repository([ 'database' => [ 'host' => '127.0.0.1', ], ]); $repository->set('database.port', 3306); $host = $repository->get('database.host'); $port = $repository->int('database.port'); $all = $repository->all();
Env Loader
use Lukman\Config\EnvLoader; $env = new EnvLoader(); $values = $env->load(__DIR__ . '/.env');
Supported scalar parsing:
trueandfalseto booleannullto null- integers and floats to numeric values
- quoted values remain strings
- empty values remain empty strings
Config File Loader
use Lukman\Config\ConfigLoader; $loader = new ConfigLoader(); $items = $loader->load(__DIR__ . '/config');
Only non-recursive *.php files are loaded. Each file must return an array. The filename becomes the namespace key.
Example config/app.php:
<?php declare(strict_types=1); return [ 'name' => 'Demo', ];
Cache
$config->cacheTo(__DIR__ . '/bootstrap/cache/config.php'); $config->loadCache(__DIR__ . '/bootstrap/cache/config.php');
Cache files are plain PHP files that return an array.
Freeze Mode
$config->freeze(); $config->get('app.name'); $config->frozen(); $config->unfreeze(); $config->set('app.name', 'Updated');
Mutation methods throw Lukman\Config\Exception\ConfigException while frozen.
Testing
composer test
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-13
