PHP code example of mikeevstropov / configuration

1. Go to this page and download the library: Download mikeevstropov/configuration library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mikeevstropov / configuration example snippets



  
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