PHP code example of wfs / custom-environment-variables

1. Go to this page and download the library: Download wfs/custom-environment-variables 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/ */

    

wfs / custom-environment-variables example snippets



Wfs\CustomEnvironmentVariables\Customizer;

$customizer = new Customizer([
    'employee' => [
        'name' => 'NAME',
        'age' => 'AGE',
    ]
]);

$target = [
    'employee' => [
        'name' => 'alice',
        'age' => '10',
    ]
];

$customized = $customizer->customize($target);

echo("name: {$customized['employee']['name']}" . PHP_EOL);
echo("age: {$customized['employee']['age']}" . PHP_EOL);


Wfs\CustomEnvironmentVariables\Customizer;
use Noodlehaus\Config;
use Noodlehaus\Parser\Yaml;

$customizer = new Customizer([
    'employee' => [
        'name' => 'NAME',
        'age' => 'AGE',
    ]
]);

$target = new Config(<<<CONF
employee:
  name: alice
  age: '10' # must be string
CONF
, new Yaml, true);

echo("name: {$target['employee']['name']}" . PHP_EOL);
echo("age: {$target['employee']['age']}" . PHP_EOL);

$customized = $customizer->customize($target);

echo("name: {$customized['employee']['name']}" . PHP_EOL);
echo("age: {$customized['employee']['age']}" . PHP_EOL);
bash
$ php usage.php
name: alice
age: 10
bash
$ export NAME=bob
$ php usage.php
name: bob
age: 10
bash
$ export NAME=bob
$ export AGE=20
$ php usage.php
name: bob
age: 20