PHP code example of mtymek / expressive-config-manager

1. Go to this page and download the library: Download mtymek/expressive-config-manager 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/ */

    

mtymek / expressive-config-manager example snippets


use Zend\Expressive\ConfigManager\ConfigManager;
use Zend\Expressive\ConfigManager\PhpFileProvider;

$configManager = new ConfigManager(
    [
        new PhpFileProvider('*.global.php'),
    ]
);

var_dump($configManager->getMergedConfig());

// db.global.php
return [
    'db' => [
        'dsn' => 'mysql:...',
    ],    
];

// cache.global.php
return [
    'cache_storage' => 'redis',
    'redis' => [ ... ],
];

array(3) {
  'db' =>
  array(1) {
    'dsn' =>
    string(9) "mysql:..."
  }
  'cache_storage' =>
  string(5) "redis"
  'redis' =>
  array(0) {
     ...
  }
}

$configManager = new ConfigManager(
    [
        function () { return ['foo' => 'bar']; },
        new PhpFileProvider('*.global.php'),
    ]
);
var_dump($configManager->getMergedConfig());

class ApplicationConfig
{
    public function __invoke()
    {
        return ['foo' => 'bar'];
    }
}

$configManager = new ConfigManager(
    [
        ApplicationConfig::class,
        new PhpFileProvider('*.global.php'),
    ]
);
var_dump($configManager->getMergedConfig());

array(4) {
  'foo' =>
  string(3) "bar"
  'db' =>
  array(1) {
    'dsn' =>
    string(9) "mysql:..."
  }
  'cache_storage' =>
  string(5) "redis"
  'redis' =>
  array(0) {
  }
}

$configManager = new ConfigManager(
    [
        function () { return [ConfigManager::ENABLE_CACHE => true]; },
        new PhpFileProvider('*.global.php'),
    ],
    'data/config-cache.php'
);

return [
    ConfigManager::ENABLE_CACHE` => true,
];

$configManager = new ConfigManager(
    [
        function () { 
            foreach (Glob::glob('data/*.global.php', Glob::GLOB_BRACE) as $file) {
                yield 

return [
    'db' => [
        'dsn' => 'mysql:...',
    ],    
];

$configManager = new ConfigManager(
    [
        new PhpFileProvider('config/*.global.php'),        
    ]
);

$configManager = new ConfigManager(
    [
        new ZendConfigProvider('*.global.json'),
        new ZendConfigProvider('database.local.ini'),
    ]
);