https://github.com/krakphp/config
Efficient and Powerful Configuration
https://github.com/krakphp/config
config ini-config json-config php-config yaml-configuration
Last synced: 2 months ago
JSON representation
Efficient and Powerful Configuration
- Host: GitHub
- URL: https://github.com/krakphp/config
- Owner: krakphp
- License: mit
- Created: 2017-05-01T04:27:47.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-05-01T04:49:55.000Z (about 8 years ago)
- Last Synced: 2025-01-29T06:52:27.126Z (4 months ago)
- Topics: config, ini-config, json-config, php-config, yaml-configuration
- Language: PHP
- Size: 10.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Config
The Config library provides a simple interface for adding configuration values. All config files are loaded lazily only when invoked providing a clean yet efficient way of managing config.
## Installation
Install with composer at `krak/config`
## Usage
All Config is managed via the ConfigStore. `Config\store` provides a default instance which will lazy load files/data and will cache the results to prevent multiple filesystem calls.
### Adding Config Items
Adding multiple entries under the same key will merge the data when it's retrieved. The entries added last will overwrite the previous entries.
```php
add('a', [
'from_array' => true,
'b' => ['c' => 1]
]);
$config->add('a', function() {
return ['from_closure' => true],
});
// You can add, php, ini, json, or yml files, but you must provide the full path
$config->add('a', __DIR__ . '/path/a.php');// or you can use this helper for files
$config->addFiles(__DIR__ . '/path', [
'a.php',
]);
$config->addPhpFiles(__DIR__ . '/path', ['a']); // this is the exact same as above
```PHP configuration files must return an array like so:
```php
true
];
```**Note:** For YAML files, you must install the Symfony YAML Component (`symfony/yaml`).
### Getting Config Items
```php
get('a'));// or retrieve nested items
$config->get('a.b.c');
```This will display something like:
```
array(4) {
["from_array"]=>
bool(true)
["from_closure"]=>
bool(true)
["from_php_file"]=>
bool(true)
}
```