publishing-kit / config
PHP configuration manager package
Requires
- php: >=7.4
- symfony/yaml: ^5.1
Requires (Dev)
- infection/infection: ^0.15.0
- mockery/mockery: ^1.3
- php-coveralls/php-coveralls: ^2.2
- phpunit/phpunit: >=8.0
- psy/psysh: ^0.9.12
- squizlabs/php_codesniffer: ^3.0
- vimeo/psalm: ^4.3
README
PublishingKit/Config is a simple config container. It can parse the following formats:
- PHP files (useful for dynamic stuff that can change based on the environment)
ini
files- YAML files
Install
Via Composer
$ composer require publishing-kit/config
Usage
You can simply pass in an array for the configuration:
$values = [ 'foo' => 'bar' ]; $config = new PublishingKit\Config\Config($values); echo $config->get('foo'); // returns 'bar'
However, in practice you're unlikely to do this. Instead, you will normally use the named constructors to create the config from a file:
$config = PublishingKit\Config\Config::fromFile('config.php'); $multiConfig = PublishingKit\Config\Config::fromFiles([ 'config.php', 'config.ini', 'config.yml' ]);
Once you have a config object, you can check for existence with the has()
method, and get the value with the get()
method, or as a property:
$config->has('foo'); // returns true $config->get('foo'); // returns 'bar' $config->foo; // returns 'bar'
Since the config object implements ArrayAccess
and IteratorAggregate
, you can also loop over them or access properties using array notation.
Config objects are immutable and so cannot be changed once created.
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email 450801+matthewbdaly@users.noreply.github.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.