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 haveYou have to set the allow override option to true, default is falseRemoved 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' ];
统计信息
- 总下载量: 62
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 5
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-08-17