Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

zendframework/zend-config-aggregator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

6239e78 · Jan 20, 2020
Dec 27, 2019
Dec 27, 2019
Dec 27, 2019
Dec 8, 2016
Jan 10, 2017
Nov 8, 2017
Nov 8, 2017
Feb 14, 2019
Dec 27, 2019
Nov 8, 2017
Jan 20, 2020
Dec 27, 2019
Dec 27, 2019
Jan 22, 2018
Dec 8, 2016
Dec 8, 2016

zend-config-aggregator

Repository abandoned 2019-12-31

This repository has moved to laminas/laminas-config-aggregator.

Build Status Coverage Status

Aggregates and merges configuration, from a variety of formats. Supports caching for fast bootstrap in production environments.

Usage

The standalone ConfigAggregator can be used to merge PHP-based configuration files:

use Zend\ConfigAggregator\ConfigAggregator;
use Zend\ConfigAggregator\PhpFileProvider;

$aggregator = new ConfigAggregator([
    new PhpFileProvider('*.global.php'),
]);

var_dump($aggregator->getMergedConfig());

Using this provider, each file should return a PHP array:

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

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

Result:

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

Configuration is merged in the same order as it is passed, with later entries having precedence.

Together with zend-config, zend-config-aggregator can be also used to load configuration in different formats, including YAML, JSON, XML, or INI:

use Zend\ConfigAggregator\ConfigAggregator;
use Zend\ConfigAggregator\ZendConfigProvider;

$aggregator = new ConfigAggregator([
    new ZendConfigProvider('config/*.{json,yaml,php}'),
]);

For more details, please refer to the documentation.