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

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

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

yohns/config

最新稳定版本:1.3.0

Composer 安装命令:

composer create-project yohns/config

包简介

Loading files in config folder and set in an array for use later.

README 文档

README

Config

Base configuration class that stores the value from returning arrays in php files.

Methods

Name Description
__construct Config constructor.
get Retrieves a configuration value.
getAll Retrieve all configuration values for file.
getCustom Retrieves a custom configuration value.
reload Reloads configurations from a specified directory.
set Sets a configuration value.

ConfigEditor

Tip

Add, Edit, and Create Configs

  • Create new config files (for new repos that may get added?),
  • Add new key => value pairs to a config file already found.
  • Edit values for predefined configs, you have
    • You have to set the allow override option to true, default is false Removed editing because it doubles up the same key.

Methods

Name Description
addToConfig Adds key-value pairs to a configuration array if they do not already exist in the specified configuration file. If the file does not exist, it creates a new configuration file with the provided data.

Put all config files in 1 directory and then call that directory and it'll load all the config files to the variable

Check out the Example File

Use composers autoload or include path to the Core/Config.php file

Example using Config

use Yohns\Core\Config;

include('vendor/autoload.php');

$dir = __DIR__.'/lib/Config';

// Initialize Config with a specific directory
new Config($dir);

// Get a configuration value
echo Config::get('users', 'db_tables').PHP_EOL;

// Set a custom configuration value
Config::set('api_key', '12345');

// Retrieve a custom configuration value
echo Config::getCustom('api_key').PHP_EOL;

Example ConfigEditor

use Yohns\Core\Config;
use Yohns\Core\ConfigEditor;

include('vendor/autoload.php');

$dir = __DIR__.'/lib/Config';

// Initialize Config with a specific directory
new Config($dir);

// Editor class allows us to append key=>values to the config files, or create a new config file if not found.
ConfigEditor::addToConfig(
	['add-new' => 'value'],
	'default',
	// only set to true if you want to "edit" the value if found in config file already.
	// default is false.
	true);
Config::reload($dir);

// get from the 'default' configs do not need to mention the file in get()
echo Config::get('add-new').PHP_EOL;

Example code uses the config/ directory found in this repo.

config/default.php:

<?php
return [
	'siteName' => 'Testing'
];

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-08-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固