Download the PHP package lorenzoferrarajr/lfj-configuration-builder without Composer
On this page you can find all versions of the php package lorenzoferrarajr/lfj-configuration-builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lorenzoferrarajr/lfj-configuration-builder
More information about lorenzoferrarajr/lfj-configuration-builder
Files in lorenzoferrarajr/lfj-configuration-builder
Package lfj-configuration-builder
Short Description A PHP library to build array configuration from various sources
License MIT
Homepage https://github.com/lorenzoferrarajr/lfj-configuration-builder
Informations about the package lfj-configuration-builder
lfj-configuration-builder
A PHP library to merge configuration arrays.
Installation
The suggested installation method is via composer:
Usage
Instantiate a ConfigurationBuilder
object, add configurations, call the build
method to get the merged array. Zend\Stdlib\ArrayUtils::merge
is used for merging.
Adding configurations
The ConfigurationBuilder
provides various methods that can be used to add configurations:
addFile
: to add a single php file returning an arrayaddFiles
: to add multiple filesaddDirectory
: to add files located inside a directoryaddArray
: to add configuration from array
Exceptions
To catch exceptions the build
method can be called inside a try
block. Available exceptions are:
FileNotExistsException
FileNotReadableException
NotArrayException
: if a configuration file does not return an arrayNotFileException
Examples
For the examples two configuration files are be used: mail.global.php
and mail.local.php
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.
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.
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
.
More information on patterns can be found in the glob documentation.
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.