2017 © Pedro Peláez
 

library lfj-configuration-builder

A PHP library to build array configuration from various sources

image

lorenzoferrarajr/lfj-configuration-builder

A PHP library to build array configuration from various sources

  • Friday, December 4, 2015
  • by lorenzoferrarajr
  • Repository
  • 1 Watchers
  • 2 Stars
  • 32 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

lfj-configuration-builder

A PHP library to merge configuration arrays., (*1)

Build Status, (*2)

Installation

The suggested installation method is via composer:, (*3)

composer require lorenzoferrarajr/lfj-configuration-builder

Usage

Instantiate a ConfigurationBuilder object, add configurations, call the build method to get the merged array. Zend\Stdlib\ArrayUtils::merge is used for merging., (*4)

Adding configurations

The ConfigurationBuilder provides various methods that can be used to add configurations:, (*5)

  • addFile: to add a single php file returning an array
  • addFiles: to add multiple files
  • addDirectory: to add files located inside a directory
  • addArray: to add configuration from array

Exceptions

To catch exceptions the build method can be called inside a try block. Available exceptions are:, (*6)

  • FileNotExistsException
  • FileNotReadableException
  • NotArrayException: if a configuration file does not return an array
  • NotFileException

Examples

For the examples two configuration files are be used: mail.global.php and mail.local.php, (*7)

<?php
// mail.global.php

return array(
    'mail' => array(
        'host' => 'localhost',
        'port' => 25
    )
);
<?php
// mail.local.php

return array(
    'mail' => array(
        'host' => '192.168.1.1',
    )
);

Building configuration from single files

In this example two files are passed to the ConfigurationBuilder object: first the mail.global.php file and then mail.local.php. The result will be an array containing the port of the first and the host of the second., (*8)

$cb = new \Lfj\ConfigurationBuilder\ConfigurationBuilder();

$cb->addFile(__DIR__.'/config/mail.global.php');
$cb->addFile(__DIR__.'/config/mail.local.php');

$config = $cb->build();

Building configuration from multiple files at once

This example is the same as the previous one but files are passed all at once as an array., (*9)

$cb = new \Lfj\ConfigurationBuilder\ConfigurationBuilder();

$cb->addFiles(array(
    __DIR__.'/config/mail.global.php',
    __DIR__.'/config/mail.local.php',
));

$config = $cb->build();

Building configuration from a directory

In this example configuration files are loaded from a directory. The pattern used for file matching is the same as global($pattern, GLOB_BRACE), so first mail.global.php and then mail.local.php., (*10)

$cb = new \Lfj\ConfigurationBuilder\ConfigurationBuilder();

$cb->addDirectory(__DIR__.'/config/*.{global,local}.php');

$config = $cb->build();

More information on patterns can be found in the glob documentation., (*11)

Building configuration from a directory and array

This example is the same as the previous but before calling the build method a new configuration is provided by passing an array., (*12)

$cb = new \Lfj\ConfigurationBuilder\ConfigurationBuilder();

$cb->addDirectory(__DIR__.'/config/*.{global,local}.php');
$cb->addArray(array(
    'mail' => array(
        'host' => 'other'
    )
));

$config = $cb->build();

The Versions

04/12 2015

dev-master

9999999-dev https://github.com/lorenzoferrarajr/lfj-configuration-builder

A PHP library to build array configuration from various sources

  Sources   Download

MIT

The Requires

 

The Development Requires

04/12 2015

0.2.2

0.2.2.0 https://github.com/lorenzoferrarajr/lfj-configuration-builder

A PHP library to build array configuration from various sources

  Sources   Download

MIT

The Requires

 

The Development Requires

08/10 2015

0.2.1

0.2.1.0 https://github.com/lorenzoferrarajr/lfj-configuration-builder

A PHP library to build array configuration from various sources

  Sources   Download

MIT

The Requires

 

The Development Requires

29/09 2015

0.2.0

0.2.0.0 https://github.com/lorenzoferrarajr/lfj-configuration-builder

A PHP library to build array configuration from various sources

  Sources   Download

MIT

The Requires

 

The Development Requires

27/09 2015

0.1.1

0.1.1.0 https://github.com/lorenzoferrarajr/lfj-configuration-builder

A PHP library to build array configuration from various sources

  Sources   Download

MIT

The Requires

 

The Development Requires

26/09 2015

0.1.0

0.1.0.0 https://github.com/lorenzoferrarajr/lfj-configuration-builder

A PHP library to build array configuration from various sources

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires