2017 © Pedro Peláez
 

library lib-config

Configuration library of the Ride framework

image

ride/lib-config

Configuration library of the Ride framework

  • Thursday, September 8, 2016
  • by ride-user
  • Repository
  • 7 Watchers
  • 1 Stars
  • 3,325 Installations
  • PHP
  • 13 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 15 Versions
  • 2 % Grown

The README.md

Ride: Configuration Library

Configuration library of the PHP Ride framework., (*1)

What's In This Library

Config

The Config interface defines a configuration data container used to get and set parameters. A generic implementation is provided., (*2)

ConfigIO

To read and write the configuration from the data source, the ConfigIO interface is used. Out of the box, you can create a ParserConfigIO with a parser of your choice wrapped around the file browser of ride-lib-system. You can wrap any IO around the CachedConfigIO to improve performance., (*3)

Parser

The Parser interface is used to read and write different file formats. An ini and json implementation are provided., (*4)

Code Sample

Check this code sample to see the possibilities of this library:, (*5)

<?php

use ride\library\config\io\CachedConfigIO;
use ride\library\config\io\ParserConfigIO;
use ride\library\config\parser\JsonParser;
use ride\library\config\ConfigHelper;
use ride\library\config\GenericConfig;
use ride\library\system\file\browser\FileBrowser;

function foo(FileBrowser $fileBrowser) {
    // Create the config helper, our IO and the config itself will use this.
    $configHelper = new ConfigHelper();

    // Let's use the JSON format...
    $parser = new JsonParser();

    // Now we create a config input/output implementation for all config/parameters.json files found in the file browser
    $configIO = new ParserConfigIO($fileBrowser, $configHelper, $parser, 'parameters.json', 'config');

    // optionally, you can wrap it around a cached version
    $cacheFile = $fileBrowser->getFileSystem()->getFile(__DIR__ . '/config.cache');
    $configIO = new CachedConfigIO($configIO, $cacheFile);

    // As final step, we create the config instance which is the main access point to the configuration parameters.
    $config = new GenericConfig($configIO, $configHelper);

    // You can get a value, optionally with a default.
    $name = $config->get('system.name'); // null, not set
    $name = $config->get('system.name', 'Ride'); // 'Ride' as default value

    // You can set a value, which is automatically written to the IO.
    $config->set('system.name', 'My System');
    $config->set('system.secret', 'ABCDEF');

    // You can get parameters which are not leafs of the configuration tree
    $parameters = $config->get('system');
    // [
    //  'name' => 'My System',
    //  'secret' => 'ABCDEF'
    // ]

    // you can use the config helper to flatten a structure
    $config->set('system.directory.cache', 'cache');
    $config->set('system.directory.template', 'templates');

    $parameters = $config->get('system');
    // [
    //  'name' => 'My System',
    //  'secret' => 'ABCDEF'
    //  'directory' => [
    //    'cache' => 'cache',
    //    'template' => 'templates',
    //  ]
    // ]

    $parameters = $configHelper->flattenConfig($parameters);
    // [
    //  'name' => 'My System',
    //  'secret' => 'ABCDEF'
    //  'directory.cache' => 'cache',
    //  'directory.template' => 'templates',
    // ]
}

Limitations

You cannot have a value for a key which has subkeys. This means, if you have a value for a key called system.directory.cache, you can not have a value for system.directory., (*6)

Installation

You can use Composer to install this library., (*7)

composer require ride/lib-config

The Versions

08/09 2016

dev-master

9999999-dev

Configuration library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

08/09 2016

dev-develop

dev-develop

Configuration library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

08/09 2016

1.0.1

1.0.1.0

Configuration library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

01/07 2016

1.0.0

1.0.0.0

Configuration library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

08/02 2016

0.4.1

0.4.1.0

Configuration library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

27/09 2015

0.4.0

0.4.0.0

Configuration library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

14/08 2015

0.3.1

0.3.1.0

Configuration library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

12/05 2015

0.3.0

0.3.0.0

Configuration library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

20/01 2015

0.2.5

0.2.5.0

Configuration library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

16/12 2013

0.2.4

0.2.4.0

Configuration library of the Pallo framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

11/11 2013

0.2.3

0.2.3.0

Configuration library of the Pallo framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

22/10 2013

0.2.2

0.2.2.0

Configuration library of the Pallo framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

20/10 2013

0.2.1

0.2.1.0

Configuration library of the Pallo framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

14/10 2013

0.2.0

0.2.0.0

Configuration library of the Pallo framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

10/10 2013

0.1.0

0.1.0.0

Configuration library of the Pallo framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd