PHPackages                             yohns/config - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. yohns/config

ActiveProject

yohns/config
============

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

1.3.0(5mo ago)199↓100%6MITPHPPHP ^8.0

Since Aug 18Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/Yohn/Config)[ Packagist](https://packagist.org/packages/yohns/config)[ RSS](/packages/yohns-config/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (1)Versions (7)Used By (6)

Yohns\\Core\\Config
===================

[](#yohnscoreconfig)

[Config](docs/Config.md)
------------------------

[](#config)

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

### Methods

[](#methods)

NameDescription[\_\_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)
------------------------------------

[](#configeditor)

Tip

Add, Edit, and Create Configs

- Create new config files (for new repos that may get added?),
- Add new key =&gt; 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 falseRemoved editing because it doubles up the same key.

### Methods

[](#methods-1)

NameDescription[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

[](#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

[](#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:
===================

[](#configdefaultphp)

```
