bshirey/hierarchical-config

There is no license information available for the latest version (v1.1.3) of this package.

Provides inheritance and hierarchical configuration tools.

v1.1.3 2015-06-26 15:45 UTC

This package is not auto-updated.

Last update: 2020-05-19 11:39:35 UTC


README

======================

Documentation on its way. This is a tool to assist in creating hierarchical configurations, where layers of configuration data are merged, with higher layers overwriting lower layers.

How To Use

============

First, you must add this library to your project. If you are using composer, try this: > composer require bshirey/hierarchical-config:1.*

This library does not do much on its own, but requires some setup in your project. At a minimum, you must implement your own ConfigBuilder with a custom implementation of the build() function. The ConfigBuilder is responsible to instantiating ConfigInterface objects. The ConfigBuilder is responsible for stacking ConfigInterface objects hierarchically.

For example:

    public class MyApplicationConfigBuilder implements ConfigBuilder
    {
        public function build($options = array())
        {
            $config = new GenericConfig($options);
            $config
                ->push(new FileConfig($options))
                ->push(new GlobalsConfig($options))
                ->push(new EnvConfig($options));

            return $config;
        }
        ...

Then your application needs to setup the ConfigFactory singleton, similar to the following:

    ConfigFactory::getInstance()
                ->setOptions($options)
                ->setBuilder(new MyApplicationConfigBuilder());

Finally, you must make your configurable classes / objects use the HierarchicalConfig\Configurable trait:

    use HierarchicalConfig\Configurable;

    public class MyApplicationClass
    {
       use Configurable;
       ...

How To Run The Tests

======================

This glosses over the details a bit. Needless to say you need to have composer installed as well as phpunit and any dependencies.

  • Run composer install if you haven't already. This installs project dependencies.
  • Run phpunit.
  • Let the tests run.