PHP code example of fluix / fconfig

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

    

fluix / fconfig example snippets




cret is a random string with length of 16 characters, which is used for encrypting/decrypting your secure configuration.
// Example of generating secret via openssl: openssl rand -hex 8
$secret = "ff7f8dc665734d9d"; // don't use this secret in your application, generate a new one and store it in a safe place.

$config = \Fluix\Config\Factory::config(
    $secret,
    null,
    "postProcessor"
);

$pathToConfig = __DIR__ . "/config/config.json";
$configFolder = __DIR__ . "/config/_generated";

$config->dump(
    \Fluix\Config\Template::fromPath($pathToConfig),
    $const = \Fluix\Config\Dump\Destination::create($configFolder, \Fluix\Config\Dump\Format::const()),
    $yaml = \Fluix\Config\Dump\Destination::create($configFolder, \Fluix\Config\Dump\Format::yaml()),
    $array = \Fluix\Config\Dump\Destination::create($configFolder, \Fluix\Config\Dump\Format::php()),
    $json = \Fluix\Config\Dump\Destination::create($configFolder, \Fluix\Config\Dump\Format::json())
);

echo "Config has been successfully dumped to {$const}" . PHP_EOL;
echo "Config has been successfully dumped to {$yaml}" . PHP_EOL;
echo "Config has been successfully dumped to {$array}" . PHP_EOL;
echo "Config has been successfully dumped to {$json}" . PHP_EOL;

function postProcessor(\Fluix\Config\ParserResult $result)
{
    // extra actions could be performed here
    // e.g. nginx.conf could be generated withing the parsed data
}



cret is a random string with length of 16 characters, which is used for encrypting/decrypting your secure configuration.
// Example of generating secret via openssl: openssl rand -hex 8
$secret             = "ff7f8dc665734d9d"; // don't use this secret in your application, generate a new one and store it in a safe place.
$pathToFallbackFile = __DIR__ . "/fallback.json";
$pathToConfig       = __DIR__ . "/config/config.json";
$configFolder       = __DIR__ . "/config/_generated";

$config = \Fluix\Config\Factory::config(
    $secret,
    Fluix\Config\File::fromPath($pathToFallbackFile),
    "postProcessor"
);

$config->dump(
    \Fluix\Config\Template::fromPath($pathToConfig),
    $const = \Fluix\Config\Dump\Destination::create($configFolder, \Fluix\Config\Dump\Format::const()),
    $yaml = \Fluix\Config\Dump\Destination::create($configFolder, \Fluix\Config\Dump\Format::yaml()),
    $array = \Fluix\Config\Dump\Destination::create($configFolder, \Fluix\Config\Dump\Format::php()),
    $json = \Fluix\Config\Dump\Destination::create($configFolder, \Fluix\Config\Dump\Format::json())
);

function postProcessor(\Fluix\Config\ParserResult $result)
{
    // extra actions could be performed here
    // e.g. nginx.conf could be generated withing the parsed data
}


// generated by Fluix\Config\Dump\PhpConstDumper, do not edit
define('option1', 'value1');
define('database', 'schema-overridden');
define('boolean', false);
define('null', NULL);
define('secret_value', 'secret-value-here');
define('int', 397);
define('object', array (
  'key' => 21,
));
define('array', array (
  0 => 
  array (
    'option31' => 'test_env',
  ),
));
define('nested', array (
  'child1' => 
  array (
    'child2' => 
    array (
      'env' => 'test_env_value_json2',
    ),
  ),
));


// generated by Fluix\Config\Dump\PhpDumper, do not edit
return array (
  'option1' => 'value1',
  'database' => 'schema-overridden',
  'boolean' => false,
  'null' => NULL,
  'secret_value' => 'secret-value-here',
  'int' => 397,
  'object' => 
  array (
    'key' => 21,
  ),
  'array' => 
  array (
    0 => 
    array (
      'option31' => 'test_env',
    ),
  ),
  'nested' => 
  array (
    'child1' => 
    array (
      'child2' => 
      array (
        'env' => 'test_env_value_json2',
      ),
    ),
  ),
);

your-app
├── composer.json
├── composer.lock
├── config
│   ├── _generated
│   ├── config.json
│   └── default.json
├── dump-config.php
└── vendor
    ├── autoload.php
    ├── bin
    ├── composer
    ├── fluix
    ├── readdle
    └── symfony
bash
cd your-app
ENV_VARIABLE1=test_env ENV_VARIABLE2=test_env_2 php dump-config.php
bash
echo "{\"ENV_VARIABLE2\":\"test_env_2\"}" > your-app/fallback.json

cd your-app
ENV_VARIABLE1=test_env php dump-config.php

your-app
├── composer.json
├── composer.lock
├── {fallback.json}
├── config
│   ├── _generated
│   │   ├── config.array.php
│   │   ├── config.const.php
│   │   ├── config.json
│   │   └── config.parameters.yml
│   ├── config.json
│   └── default.json
├── dump-config.php
└── vendor
    ├── autoload.php
    ├── bin
    ├── composer
    ├── fluix
    ├── readdle
    └── symfony