https://github.com/ellisgl/geeklab-conf
Configuration system for PHP >= 8.1
https://github.com/ellisgl/geeklab-conf
array configuration environment ini json php php7 php7-4 php74 php81 yaml
Last synced: 4 months ago
JSON representation
Configuration system for PHP >= 8.1
- Host: GitHub
- URL: https://github.com/ellisgl/geeklab-conf
- Owner: ellisgl
- License: bsd-3-clause
- Created: 2018-11-21T04:44:36.000Z (over 7 years ago)
- Default Branch: release
- Last Pushed: 2022-11-24T21:39:52.000Z (over 3 years ago)
- Last Synced: 2025-06-05T06:53:16.852Z (about 1 year ago)
- Topics: array, configuration, environment, ini, json, php, php7, php7-4, php74, php81, yaml
- Language: PHP
- Homepage:
- Size: 396 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.BSD
Awesome Lists containing this project
README
[](https://opensource.org/licenses/BSD-3-Clause)
[](https://github.com/phpstan/phpstan)
[](https://scrutinizer-ci.com/g/ellisgl/GeekLab-Conf/?branch=release)
[](https://scrutinizer-ci.com/g/ellisgl/GeekLab-Conf/?branch=release)
# geeklab/conf
Immutable configuration system loader & parser for PHP >= 8.1 that supports multiple file formats and has some templating features.
This library is an alternative to '.env' type configuration libraries and uses the [Strategy Pattern](https://designpatternsphp.readthedocs.io/en/latest/Behavioral/Strategy/README.html).
### [Benchmarks](https://github.com/ellisgl/php-benchmarks/blob/master/results/Confs.md)
## Latest
4.0.0 (2020-11-24): Updating to more >= 8.1.0 compatible.
## Features:
* Multi-file configuration loading, no more monolithic configurations!
* Self referencing placeholders. ```@[X.Y.Z]```
* Recursive self referencing placeholders. ```@[@[X.Y.Z].SOME_KEY]```
* Environment variable placeholders. ```$[ENVIRONMENT_VARIABLE_NAME]``` (PHP likes ```${YOUR_TEXT_HERE}``` a little too much...)
* Can use INI, JSON, YAML and Array files.
* Immutability, since you shouldn't change your configuration during run time.
* Can inject values, to make things really dynamic.
## Installation:
composer require geeklab/conf
## Usage:
Basic:
```PHP
// Where the configurations are.
$configurationDirectory = __DIR__ . '/config/';
// Load Configuration system with the JSON Configuration Driver
$configuration = new GLConf(
new JSONConfDriver(
$configurationDirectory . 'system.json', // Path and file name of main (top level) configuration.
$configurationDirectory // Path to the other configuration files.
),
['mySecretKey' => md5(rand())], // Value injections.
['keys_to_lower'] // Options:
// Options to change the case of the key if returning a keyed array:
// keys_upper_case, keys_lower_case, keys_same_case
);
$configuration->init();
// Get the whole configuration.
var_export($configuration->getAll());
// Get one item.
var_export($configuration->get('space_pants.look_at_my'));
```
Detailed:
* [INI](/docs/INI.md)
* [Array](/docs/Array.md)
* [JSON](/docs/JSON.md)
* [YAML](/docs/YAML.md)
PSR Compliance:
* PSR-1
* PSR-2
* PSR-4
* PSR-12
## Todo:
* More Documentation.
* Include .env?