PHP code example of jenson / convict

1. Go to this page and download the library: Download jenson/convict 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/ */

    

jenson / convict example snippets


$scheme = '{
  "about": "Special keyword containing a short description of the program",
  "key": {
    "to": {
      "value": {
        "doc": "A value that we can set and get",
        "format": "*",
        "arg": "value",
        "shortarg": "v",
        "env": "PHP_VALUE",
        "default": "foo bar"
      }
    }
  }
}';

$config = new \Convict\Convict($scheme);

$config->validate();

$config->set('key.to.value', 'a value');
$config->get('key.to.value');
$config->get('key');

$config->set('a', 'x');
$config->get('a'); // => string 'x'

$config->set('a.b', 'y');
$config->get('a'); // => array ('b' => 'y')

$config->set('a.c', 'z');
$config->get('a'); // => array ('b' => 'y', 'c' => 'z')


$config->loadFile('path/to/file');

$config->writeConfig('path/to/file');

$config = new \Convict\Convict($scheme, [ 'nohelp' => true ]);
bash
PHP_VALUE=val php demo.php
php demo.php --value=val
php demo.php --value val
php demo.php -vval
php demo.php --help