2017 © Pedro Peláez
 

library config-loader

Generic config loader with context and environment support.

image

helhum/config-loader

Generic config loader with context and environment support.

  • Monday, June 25, 2018
  • by helhum
  • Repository
  • 4 Watchers
  • 6 Stars
  • 77,521 Installations
  • PHP
  • 10 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 15 Versions
  • 46 % Grown

The README.md

Configuration Loader Build Status

This is just a class, which helps you to merge a base configuration with configuration from different contexts and the environment., (*1)

Just require it using composer: composer require helhum/config-loader, (*2)

Basic usage

$context = 'production';
$confDir = '/path/to/conf';
$configReaderFactory = new \Helhum\ConfigLoader\ConfigurationReaderFactory($confDir);
$configLoader = new \Helhum\ConfigLoader\ConfigurationLoader(
    [
        $configReaderFactory->createReader($confDir . '/default.php'),
        $configReaderFactory->createReader($confDir . '/' . $context . '.php'),
        $configReaderFactory->createReader('PREFIX', ['type' => 'env']),
        $configReaderFactory->createReader($confDir . '/override.php'),
    ]
);
$config = $configLoader->load();

Basic usage cached

$context = 'production';
$confDir = '/path/to/conf';
$cacheDir = '/path/to/cache';
$cacheIdentifier = md5($context . filemtime('/path/to/.env'));
$configReaderFactory = new \Helhum\ConfigLoader\ConfigurationReaderFactory($confDir);
$configLoader = new \Helhum\ConfigLoader\CachedConfigurationLoader(
    $cacheDir,
    $cacheIdentifier,
    function() use ($confDir, $context, $configReaderFactory) {
        return new \Helhum\ConfigLoader\ConfigurationLoader(
            [
                $configReaderFactory->createReader($confDir . '/default.php'),
                $configReaderFactory->createReader($confDir . '/' . $context . '.php'),
                $configReaderFactory->createReader('PREFIX', ['type' => 'env']),
                $configReaderFactory->createReader($confDir . '/override.php'),
            ]
        );
    }
);
$config = $configLoader->load();

Using processors

It is possible to add one or more processors to the config loader., (*3)

$context = 'production';
$confDir = '/path/to/conf';
$configReaderFactory = new \Helhum\ConfigLoader\ConfigurationReaderFactory($confDir);
$configLoader = new \Helhum\ConfigLoader\ConfigurationLoader(
    [
        $configReaderFactory->createReader($confDir . '/config.php'),
    ],
    [
        new \Helhum\ConfigLoader\Processor\PlaceholderValue(),
    ]
);
$config = $configLoader->load();

Advanced usage

Instead of hard coding which configuration sources should be included, it is possible to include multiple sources from within one configuration file., (*4)

$context = 'production';
$confDir = '/path/to/conf';
$configReaderFactory = new \Helhum\ConfigLoader\ConfigurationReaderFactory($confDir);
$configLoader = new \Helhum\ConfigLoader\ConfigurationLoader(
    [
        $configReaderFactory->createRootReader($confDir . '/config.yaml'),
    ]
);
$config = $configLoader->load();

The configuration file can then include an import section:, (*5)

imports:
    - { resource: 'config.*.yml', type: glob }
    - { resource: 'env.yml' }

Feedback

Any feedback is appreciated. Please write bug reports, feature request, create pull requests, or just drop me a "thank you" via Twitter or spread the word., (*6)

Thank you!, (*7)

The Versions

25/06 2018

dev-master

9999999-dev

Generic config loader with context and environment support.

  Sources   Download

GPL-2.0+ GPL-2.0-or-later

The Requires

  • php >=7.0.0 <7.3.0

 

The Development Requires

25/06 2018

v0.10.0

0.10.0.0

Generic config loader with context and environment support.

  Sources   Download

GPL-2.0-or-later

The Requires

  • php >=7.0.0 <7.3.0

 

The Development Requires

14/06 2018

v0.9.0

0.9.0.0

Generic config loader with context and environment support.

  Sources   Download

GPL-2.0-or-later

The Requires

  • php >=7.0.0 <7.3.0

 

The Development Requires

27/02 2018

v0.8.0

0.8.0.0

Generic config loader with context and environment support.

  Sources   Download

GPL-2.0-or-later

The Requires

  • php >=7.0.0 <7.3.0

 

The Development Requires

25/02 2018

v0.7.1

0.7.1.0

Generic config loader with context and environment support.

  Sources   Download

GPL-2.0-or-later

The Requires

  • php >=7.0.0 <7.3.0

 

The Development Requires

15/02 2018

v0.7.0

0.7.0.0

Generic config loader with context and environment support.

  Sources   Download

GPL-2.0-or-later

The Requires

  • php >=7.0.0 <7.3.0

 

The Development Requires

05/02 2018

v0.6.0

0.6.0.0

Generic config loader with context and environment support.

  Sources   Download

GPL-2.0-or-later

The Requires

  • php >=7.0.0 <7.3.0

 

The Development Requires

14/06 2017

0.5.3

0.5.3.0

Generic config loader with context and environment support.

  Sources   Download

GPL-2.0+

The Requires

  • php >=7.0.0 <7.2.0

 

The Development Requires

11/06 2017

0.5.2

0.5.2.0

Generic config loader with context and environment support.

  Sources   Download

GPL-2.0+

The Requires

  • php >=7.0.0 <7.2.0

 

The Development Requires

08/06 2017

0.5.1

0.5.1.0

Generic config loader with context and environment support.

  Sources   Download

GPL-2.0+

The Requires

  • php >=7.0.0 <7.2.0

 

The Development Requires

07/06 2017

0.5.0

0.5.0.0

Generic config loader with context and environment support.

  Sources   Download

GPL-2.0+

The Requires

  • php >=7.0.0 <7.2.0

 

The Development Requires

06/06 2017

0.4.0

0.4.0.0

Generic config loader with context and environment support.

  Sources   Download

GPL-2.0+

The Requires

  • php >=7.0.0 <7.2.0

 

The Development Requires

03/06 2017

0.3.0

0.3.0.0

Generic config loader with context and environment support.

  Sources   Download

GPL-2.0+

The Development Requires

02/06 2017

0.2.0

0.2.0.0

Generic config loader with context and environment support.

  Sources   Download

GPL-2.0+

The Development Requires

03/05 2016

0.1.0

0.1.0.0

Generic config loader with context and environment support.

  Sources   Download

GPL-2.0+

The Development Requires