mikeevstropov / configuration
This package is abandoned and no longer maintained.
No replacement package was suggested.
Read and write configuration parameters to the YAML file.
1.0.4
2017-07-14 10:06 UTC
Requires
- symfony/yaml: ^3.0
- webmozart/assert: ^1.0
Requires (Dev)
- phpunit/phpunit: ^5.7
This package is not auto-updated.
Last update: 2021-06-26 10:37:18 UTC
README
Read and write configuration parameters to the YAML file.
Install
Add dependency by Composer
$ composer require mikeevstropov/configuration
Example usage
As example we have following configuration file.
# app/config/config.yml my_parameter: my_value
What we can do with it?
<?php namespace Mikeevstropov\Configuration\Configuration; // origin configuration $originFile = 'app/config/config.yml'; // modified configuration $modifiedFile = 'var/temp/config.yml'; // create instance $configuration = new Configuration( $originFile, $modifiedFile ); // get parameter $value = $configuration->get('my_parameter'); // my_value // set parameter // and save it to the file of modified configuration $configuration->set('my_parameter', 'new_value'); // check it $configuration->get('my_parameter'); // new_value // now we can remove instance or exit form runtime unset($configuration); // create instance again $configuration = new Configuration( $originFile, $modifiedFile ); // and check saved value $value = $configuration->get('my_parameter'); // new_value // it has $configuration->has('my_parameter'); // true // remove $configuration->remove('my_parameter'); // not defined $configuration->has('my_parameter'); // false // also you can use "strict getter" to get existed value // or thrown InvalidArgumentException if not $configuration->getStrict('my_parameter'); // thrown InvalidArgumentException // "strict getter" provide type hinting by second argument // and thrown InvalidArgumentException if does not match $configuration->getStrict('my_parameter', 'array'); // thrown InvalidArgumentException // method getAssert provide assertion behaviour by method // from Webmozart\Assert by second argument $configuration->getAssert('my_parameter', 'nullOrStringNotEmpty'); // new_value // arguments following the second will be passed to // the assertion method from Webmozart\Assert $configuration->getAssert('my_parameter', 'range', 10, 20); // thrown InvalidArgumentException
As you can see, when we are using setter the value will saved to the file of modified configuration and loaded next time ass well.
Development
Clone
$ git clone https://github.com/mikeevstropov/configuration.git
Go to project
$ cd configuration
Install dependencies
$ composer install
Set the permissions
$ sudo chmod 777 ./var -v -R
Try to test (PHPUnit is required in global scope)
$ composer test