PHP code example of beatlabs / load

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

    

beatlabs / load example snippets


return [
    'var' => [
        'sub-var' => 'sub-val',
        'val',
    ]   
];

$loader = new BeatLabs\Load\Loader\PHPLoader('config.php'); // Config file
$config = new BeatLabs\Load\Config([$loader]);
$config->load();

// Get configuration values
$val = $config->get('var');

$loader = new BeatLabs\Load\Loader\ConsulLoader();
$config = new BeatLabs\Load\Config([$loader]);
$config->load();

// Get configuration values
$val = $config->get('var');

// You can get all available options here: https://docs.guzzlephp.org/en/6.5/quickstart.html#creating-a-client
$options = [
    "base_uri" => "myhost:8000"
];
$loader = new BeatLabs\Load\Loader\ConsulLoader('services/my-service', $options);

$config = new BeatLabs\Load\Config([$loader]);
$config->load();

// Get configuration values
$val = $config->get('var');

// Set variable
$loader = new BeatLabs\Load\Loader\EnvLoader('PREFIX_'); // Define environment variables prefix to be loaded
$config = new BeatLabs\Load\Config([$loader]);
$config->load();

// Get configuration values
$val = $config->get('var');


$consulLoader = new BeatLabs\Load\Loader\ConsulLoader();
$fileLoader = new BeatLabs\Load\Loader\PHPLoader('config.php');
$envLoader = new BeatLabs\Load\Loader\EnvLoader('PREFIX_');
$config = new BeatLabs\Load\Config([$consulLoader, $fileLoader, $envLoader]);
$config->load();

// Get configuration values
$val = $config->get('var');

$cache = new CustomCache();
$loader = new BeatLabs\Load\Loader\PHPLoader('config.php'); // Config file
$config = new BeatLabs\Load\Config([$loader], $cache);
$config->load();

return [
    'var' => [
        'sub-var' => 'sub-val',
        'val',
    ]   
];

$loader = new BeatLabs\Load\Loader\PHPLoader('config.php'); // Config file
$config = new BeatLabs\Load\Config([$loader]);
$config->load();

// Get configuration values
$val1 = $config->get('var'); // $val = ['sub-var' => 'sub-val, 'val']
$val2 = $config->get('var.sub-var'); // $val = 'sub-val'

$loader = new BeatLabs\Load\Loader\PHPLoader('config.php'); // Config file
$config = new BeatLabs\Load\Config([$loader], null, '_');
$config->load();

// Get configuration values
$val1 = $config->get('var'); // $val = ['sub-var' => 'sub-val, 'val']
$val2 = $config->get('var_sub-var'); // $val = 'sub-val'

$config->reload();