geeklab / conf
Immutable configuration system for PHP >= 8.1
4.0.0
2022-11-24 17:09 UTC
Requires
- php: >=8.1
- symfony/yaml: ^6.1
Requires (Dev)
- phpmd/phpmd: ^2.13
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^9
- squizlabs/php_codesniffer: ^3.7
README
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.
Benchmarks
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:
// 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:
PSR Compliance:
- PSR-1
- PSR-2
- PSR-4
- PSR-12
Todo:
- More Documentation.
- Include .env?