定制 ctorh23/configmanager 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ctorh23/configmanager

最新稳定版本:v1.1.0

Composer 安装命令:

composer require ctorh23/configmanager

包简介

Configuration management library for PHP applications.

README 文档

README

ConfigManager is a lightweight library for managing PHP configuration files with support for Dot-Notation, Lazy Loading and Caching.

Installation

The package requires PHP 8.3 or newer.

composer require ctorh23/configmanager

Usage

Configuration File Structure

Create a PHP file, for example app.php, that looks like this:

return [
	'name' => 'My App',
	'env' => $this->env('APP_ENV', 'production'),
	'encryption' => [
		'cipher' => 'AES-256-GCM',
		'key' => $this->env('APP_KEY'),
	],
];

The file must return an array. As you can see, you can use environment variables as configuration settings. The second parameter of the env() method is a default value.

Accessing Configuration Values

Assuming your configuration files are saved in a config/ directory, you must pass the path to this directory to instantiate a ConfigManager object:

use Ctorh23\ConfigManager\ConfigManager;

$confMan = new ConfigManager(__DIR__ . '/config');

echo $confMan->get('app.name'); //Output: My App
echo $confMan->get('app.env'); //Output: production
echo $confMan->get('app.encryption.cipher'); //Output: AES-256-GCM

// Passing a default value as a second parameter
echo $confMan->get('app.logs', 'logs/'); //Output: logs/

You can also dynamically set configuration settings, but you should keep in mind that they are not persisted on the filesystem:

$confMan->set('timezone', 'UTC');
$confMan->set('app.encryption.cipher', 'AES-XTS');

echo $confMan->get('timezone'); //Output: UTC
echo $confMan->get('app.encryption.cipher'); //Output: AES-XTS

Caching

A configuration file is loaded once per request. When you have multiple configuration files, this can cause unnecessary filesystem access. In production, it is recommended to cache the configuration settings. A cache directory must be passed as the second argument to the ConfigManager constructor:

$confMan = new ConfigManager(__DIR__ . '/config', __DIR__ . '/cache');
$confMan->warmUpCache();

With caching enabled, the cached configuration file is loaded only once when a ConfigManager object is instantiated. If you change a setting or add a new configuration file, those changes will not be available until the cache file is deleted.

Call the warmUpCache() method as part of your deployment process. You do not need to manually delete an old cache file beforehand - it will be overwritten.

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固