rpurinton/config 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

rpurinton/config

最新稳定版本:1.0.25

Composer 安装命令:

composer require rpurinton/config

包简介

A basic configuration loading utility.

README 文档

README

This directory contains the configuration management system for the RPurinton project. The primary component is the Config class, which provides a robust mechanism for handling configuration data stored in JSON format.

Overview

The Config class is designed to facilitate the management of configuration data by providing methods to read, validate, and write configuration files. It ensures that configuration files are always in a consistent state, even in the event of a system failure.

Features

  • JSON Configuration: The configuration data is stored in JSON format, allowing for easy readability and editing.
  • Automatic File Creation: If the specified configuration file does not exist, an initial empty configuration file is created automatically.
  • Validation: The class supports validation of required configuration keys and their types, ensuring that all necessary configuration data is present and correctly formatted.
  • Atomic Writes: Configuration changes are written to a temporary file and then atomically moved to the target location, preventing data corruption.
  • Error Handling: Comprehensive error handling is implemented to manage file operations and JSON encoding/decoding issues.

Usage

Initialization

To initialize a configuration, create an instance of the Config class:

use RPurinton\Config;

$config = new Config('config_name', [
    'required_key' => 'string',
    'nested_key' => [
        'sub_key' => 'int'
    ]
]);
  • config_name: The base name of the configuration file (without extension).
  • required: An associative array defining required keys and their expected types.

Reading Configuration

The configuration data can be accessed directly from the config property:

$data = $config->config;

Saving Configuration

To save changes to the configuration, use the save method:

$config->save();

Static Access

For quick access to configuration data without the need to save changes, use the static get method:

$data = Config::get('config_name', [
    'required_key' => 'string'
]);

Error Handling

The Config class throws ConfigException for any errors encountered during file operations or JSON processing. Ensure to handle these exceptions appropriately in your application.

Directory Structure

  • src/Config.php: Contains the Config class implementation.
  • config/: The directory where configuration files are stored. This directory is created automatically if it does not exist.

Requirements

  • PHP 7.4 or higher
  • JSON extension enabled

License

This project is licensed under the MIT License. See the LICENSE file for details.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固