2017 © Pedro Peláez
 

library config

Configuration file loader built on zend/config package that comes with environment support.

image

obullo/config

Configuration file loader built on zend/config package that comes with environment support.

  • Wednesday, June 20, 2018
  • by eguvenc
  • Repository
  • 1 Watchers
  • 4 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Obullo / Config

Build Status Software License Total Downloads, (*1)

Configuration file loader built on zend/config package that comes with environment support., (*2)

Install

``` bash $ composer require obullo/config, (*3)


## Requirements The following versions of PHP are supported by this version. * 7.0 * 7.1 * 7.2 ## Testing ``` bash $ vendor/bin/phpunit

Quick start

Global configuration, (*4)

require 'vendor/autoload.php';

define('ROOT', '/var/www/myproject/');
define('CONFIG_CACHE_FILE', 'cache/config.php');

use Zend\ServiceManager\ServiceManager;
use Symfony\Component\Yaml\Yaml as SymfonyYaml;
use Zend\Config\Config;
use Zend\Config\Factory;
use Zend\Config\Reader\Yaml as YamlReader;

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

$container = new ServiceManager;
$container->setService('yaml', new YamlReader([SymfonyYaml::class, 'parse']));

Factory::registerReader('yaml', $container->get('yaml'));
Factory::setReaderPluginManager($container);

$aggregator = new ConfigAggregator(
    [
        new ArrayProvider([ConfigAggregator::ENABLE_CACHE => true]),
        new ZendConfigProvider(ROOT.'config/autoload/{,*.}{json,yaml,php}'),
    ],
    CONFIG_CACHE_FILE
);
$config = $aggregator->getMergedConfig();

Create global config object, (*5)

$container->setService('config', new Config($config, true));  

Create local config object as loader, (*6)

use Obullo\Config\ConfigLoader;

$loader = new ConfigLoader(
    $config,
    CONFIG_CACHE_FILE
);
$container->setService('loader', $loader);

Reading files globally

$container->get('config')->foo->bar; // value

Reading files locally

$amqp = $container->get('loader')
        ->load(ROOT, '/config/amqp.yaml')
        ->amqp;

echo $amqp->host; // 127.0.0.1

Environment variable

An example .yaml configuration file., (*7)

# amqp
# 

amqp:
    host: 127.0.0.1
    port: 5672
    username: 'env(AMQP_USERNAME)'
    password: 'env(AMQP_PASSWORD)'
    vhost: /

Fill in sample environment variables., (*8)

putenv('AMQP_USERNAME', 'guest');
putenv('AMQP_PASSWORD', 'guest');

Add env processor to read env values., (*9)

use Obullo\Config\Processor\Env as EnvProcessor;
$loader = $container->get('loader');
$loader->addProcessor(new EnvProcessor);

$amqp = $loader->load(ROOT, '/config/amqp.yaml')
        ->amqp;

echo $amqp->username;  // guest
echo $amqp->password;  // guest

If you use '%s' in a folder path, this variable is changed with the value 'APP_ENV'., (*10)

/config/%s/amqp.yaml
/config/dev/amqp.yaml  // after replacement

The environment variable can be set with the setEnv method., (*11)

$loader = $container->get('loader');
$loader->setEnv(getenv('APP_ENV'));
$loader->addProcessor(new EnvProcessor);

$amqp = $loader->load(ROOT, '/config/%s/amqp.yaml')
        ->amqp;

echo $amqp->password;  // guest

Documentation

Documents are available at http://config.obullo.com/, (*12)

The Versions

20/06 2018

dev-master

9999999-dev http://config.obullo.com

Configuration file loader built on zend/config package that comes with environment support.

  Sources   Download

MIT

The Requires

 

The Development Requires

config zend environment reader

20/06 2018

1.0.1

1.0.1.0 http://config.obullo.com

Configuration file loader built on zend/config package that comes with environment support.

  Sources   Download

MIT

The Requires

 

The Development Requires

config zend environment reader

02/06 2018

1.0.0

1.0.0.0 http://config.obullo.com

Obullo config is a package that assumes configuration management by reading the configuration files in your application.

  Sources   Download

MIT

The Requires

 

The Development Requires

config zend reader