eig / configurator
A PHP Generic Configuration Object
Requires
- php: >=7.2
- illuminate/config: ^6.5
- symfony/finder: ^4.3
- tightenco/collect: ^6.5
Requires (Dev)
- mockery/mockery: ^1.2.2
- php-coveralls/php-coveralls: 2.1.*
- phpunit/phpunit: ^8
- symfony/var-dumper: ^4.3
This package is auto-updated.
Last update: 2021-06-01 18:50:26 UTC
README
A Configuration Loader for PHP Packages
This package is a standalone library to allow you to have easy setup and access to configuration variables in your own php packages.
Supports
PHP
- 7.2
- 7.3
Install
composer require eig/configurator
Usage
Include the Configurator class in your application:
use eig\Configurator\Configurator as Config;
Now call instantiate a copy:
$config = new Config("path/to/files");
or load in an array of values
$config = new Config($array, $key);
You can mix and match methods of loading config values.
Now you can reference your configuration variable loaded from the files supplied with dot notation on the config object:
$config->get('app.name');
You also have access to several methods:
all()
-> returns all items
get($key)
-> returns the item at the key, may be dot notation
has($key)
-> returns boolean (True/False) if the value exists, may use dot notation
load($value, $key)
-> load more values into the config object, **Note: $key
is only required for adding an array of values. For adding files the file name is used as the top level key.
Facade
To use the library through a Facade use eig\Configurator\Facades\Configurator
Then in your code you can load and access your configuration values like so:
/** * This mehtod is required first to access any configuration values * Failing to load first will return a null to any calls to items() or get() */ Configurator::load($path); /** * This method will return all items that are loaded as an array. */ Configurator::all(); /** * This method will return the item you specify just like using the array notation on a * regular Configurator instance */ Configurator::get($value); /** * This method will return true or false if the value exists in the config object */ Configurator::has($value); /** * This method sets the value provided to the key */ Configurator::set($key, $value)
Contributing
To contribute to this project clone the github repository create a new branch with the feature you are creating or bug you are fixing. Write tests to prove your feature or bugfix works then submit a pull request on github.