Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yohn/config
Simple way to load multiple config files in a dircetory into an easy callable static class
https://github.com/yohn/config
config php-config php-config-parser simple-config simpleconfig
Last synced: about 2 months ago
JSON representation
Simple way to load multiple config files in a dircetory into an easy callable static class
- Host: GitHub
- URL: https://github.com/yohn/config
- Owner: Yohn
- License: mit
- Created: 2024-08-17T23:45:54.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-10-28T09:02:20.000Z (3 months ago)
- Last Synced: 2024-11-05T09:09:16.581Z (2 months ago)
- Topics: config, php-config, php-config-parser, simple-config, simpleconfig
- Language: PHP
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Yohns\Core\Config
## [Config](docs/Config.md)
Base configuration class that stores the value from returning arrays in php files.
### Methods| Name | Description |
|------|-------------|
|[__construct](docs/#config__construct)|Config constructor.|
|[get](docs/#configget)|Retrieves a configuration value.|
|[getAll](docs/#configgetall)|Retrieve all configuration values for file.|
|[getCustom](docs/#configgetcustom)|Retrieves a custom configuration value.|
|[reload](docs/#configreload)|Reloads configurations from a specified directory.|
|[set](docs/#configset)|Sets a configuration value.|## [ConfigEditor](docs/ConfigEditor.md)
> [!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](docs/#configeditoraddtoconfig)|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](Example.php)
Use composers autoload or include path to the Core/Config.php file
### Example using Config
```php
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
```php
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
'Testing'
];
```