emargareten/config-php
最新稳定版本:v0.0.1
Composer 安装命令:
composer require emargareten/config-php
包简介
Simple config manager for PHP
关键字:
README 文档
README
This package makes it easy to manage configuration settings in your application. It provides a simple and convenient way to set, get, and manipulate configuration values.
Requirements
This package requires PHP 8.0 or later.
Installation
You can install the package via composer:
composer require emargareten/config-php
Usage
Setting the Configuration File Path
Before you can use the package, you must create a configuration file and set the path to it. The configuration file should return an array of configuration values:
<?php return [ 'key' => 'value', 'another_key' => 'another_value', ];
Now set the path to your configuration file in your application bootstrap file etc.:
Config::setPath('/path/to/config.php');
Alternatively, you can pass the path as a parameter when you instantiate the Config class for the first time:
$config = new Config('/path/to/config.php');
If you don't want to use a configuration file, you can use the setValues method to set configuration values directly:
Config::setValues([ 'key' => 'value', 'another_key' => 'another_value', ]);
Using the Configuration
The Config value are static, so you can access them anywhere in your application.
You can the following methods to get, set, and manipulate configuration values: (call these methods statically or on an instance of the Config class)
// Get a value from your configuration $value = Config::get('key'); // Get a value with a default value if key is not found $value = Config::get('key', 'default'); // Set a value in your configuration Config::set('key', 'value'); // Remove a value from your configuration Config::forget('key'); // Remove all values from your configuration Config::clear(); // Set multiple values in your configuration Config::setMany([ 'key1' => 'value1', 'key2' => 'value2', ]); // Reset your configuration to its initial state (rereads the config file) Config::reset(); // Check if a key exists in your configuration if (Config::has('key')) { // ... } // Get all values from your configuration $values = Config::all();
You can also use the config helper function to access the Config class:
config()->get('key'); // or config('key') config()->set('key', 'value'); // ...
Changelog
Please see CHANGELOG for more information about what has changed recently.
Testing
composer test
Contributing
Contributions are welcome! If you find any bugs or issues or have a feature request, please open a new issue or submit a pull request. Before contributing, please make sure to read the Contributing Guide.
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-04-18