承接 jsc-php/configs 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

jsc-php/configs

最新稳定版本:v0.1.1

Composer 安装命令:

composer require jsc-php/configs

包简介

Config file parser and writer

README 文档

README

A simple and flexible PHP library for parsing and writing configuration files. Supports JSON, YAML, INI, and XML formats with ease.

Features

  • Multi-format Support: Seamlessly handle .json, .yaml, .ini, .php, and .xml files.
  • Magic Access: Access and modify configuration data using PHP magic properties.
  • Auto-save: Automatically persists changes back to the file when the object is destroyed (can be disabled)1.
  • Format Conversion: Easily convert configuration files between supported formats.
  • Type Safety: Built for PHP 8.5+ with modern syntax.

Installation

Install via Composer:

composer require jsc-php/configs

Note: Requires the ext-yaml PHP extension for YAML support.

Usage

Basic Example

use JscPhp\Configs\Config;

// Load a config file (format is determined by file extension)
$config = new Config('test.php');

// Get values using magic methods
$db = $config->database;
$db_host = $config->database['host'];

// Get values using get function
$db = $config->get('database');
$db_host = $config->get('database')['host'];
$db_host = $config->get('database','host');
$db_host = $config->get('database.host');


// Set values
$config->debug = true;
$config->set('debug', true);
$config->set('debug.level', 'info');
$config->set(['debug','level'], 'info');

// Changes are automatically saved when $config goes out of scope

Options

You can disable autosave in the constructor:

$config = new Config('config.yaml', ['autosave' => false]);

$config->theme = 'dark';

// Manual save required if autosave is false
$config->save();

Converting Formats

Convert an existing configuration to a different format:

use JscPhp\Configs\Config;
use JscPhp\Configs\Types\Type;

$config = new Config('settings.ini');

// Save as JSON
$config->saveAs('settings.json');

Deleting Keys

$config->delete('key1'); //Deletes array key1
$config->delete('key1.key2'); //Deletes array key2 within key1
$config->delete('key1','key2'); //Deletes array key2 within key1

Supported Formats

  • JSON: Uses native json_encode and json_decode.
  • YAML: Uses yaml_emit and yaml_parse (requires ext-yaml).
  • INI: Uses parse_ini_file with typed scanning and a custom writer supporting sections and multi-value keys.
  • PHP: Uses var_export() to create a return value
  • XML: Uses SimpleXML for parsing and DOM for formatted output with proper indentation.

License

This project is licensed under the GPL-3.0 License.

Authors

Footnotes

  1. To save changes, the config file must be writable

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2026-01-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固