2017 © Pedro Peláez
 

library config

Configuration module for UserFrosting

image

userfrosting/config

Configuration module for UserFrosting

  • Friday, April 20, 2018
  • by alexweissman
  • Repository
  • 5 Watchers
  • 1 Stars
  • 10,185 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 8 Versions
  • 12 % Grown

The README.md

Config module for UserFrosting 4

Latest Version Software License Join the chat at https://chat.userfrosting.com/channel/support Donate, (*1)

Branch Build Coverage Style
master [![][config-master-build]][config-travis] ![][config-style-master]
develop [![][config-develop-build]][config-travis]  

Usage

Create a file default.php, in a directory /path/to/core/config/:, (*2)

default.php, (*3)

return [
    'contacts' => [
        'housekeeper' => [
            'name' => 'Alex',
            'email' => 'alex@cleansthetoilet.com'
        ]
    ]
];

Suppose now you have another config file which can override values in this base config file. For example, in /path/to/plugin/config/, you have:, (*4)

default.php, (*5)

return [
    'contacts' => [
        'housekeeper' => [
            'name' => 'Alex "the man" Weissman'
        ]
    ]
];

You can generate an ordered list of these configuration files using the ConfigPathBuilder class, and merge them together using an instance of UserFrosting\Support\Respository\Loader\ArrayFileLoader., (*6)

Path builder

Create ResourceLocator and ConfigPathBuilder classes to build a list of configuration files:, (*7)

$locator = new ResourceLocator(__DIR__);
$locator->registerLocation('core', 'path/to/core');
$locator->registerLocation('plugin', 'path/to/plugin');
$locator->registerStream('config', '', 'config/');

$builder = new ConfigPathBuilder($locator, 'config://');
$paths = $builder->buildPaths();

// Generates a list of paths:
[
    '/core/config/default.php'
    '/plugin/config/default.php'
]

Data loader

You can then use the ArrayFileLoader class to load and merge all configuration data from this list of paths:, (*8)

$loader = new \UserFrosting\Support\Respository\Loader\ArrayFileLoader($builder->buildPaths());
$config = new \UserFrosting\Support\Respository\Repository($loader->load());

Config files in multiple paths will be merged in the order in which the paths are specified. You can now access your configuration data via the standard Repository methods:, (*9)

echo $config->get('contacts.housekeeper.name');
// Prints 'Alex'

You can also specify environment-specific config files in each path. If an environment name is passed to buildPaths(), ConfigPathBuilder will merge in the environment-specific file in a path immediately after merging in default.php:, (*10)

development.php, (*11)

return [
    'database' => [
        'password' => 'sup3rC-cr3t'
    ]
];

To merge this in, you would call:, (*12)

$paths = $builder->buildPaths('development');

Style Guide

Testing

The Versions

20/04 2018

dev-feature-locator

dev-feature-locator https://github.com/userfrosting/config

Configuration module for UserFrosting

  Sources   Download

MIT

The Requires

 

The Development Requires

configuration config userfrosting

18/06 2017

dev-master

9999999-dev https://github.com/userfrosting/config

Configuration module for UserFrosting

  Sources   Download

MIT

The Requires

 

The Development Requires

configuration config userfrosting

18/06 2017

4.1.0

4.1.0.0 https://github.com/userfrosting/config

Configuration module for UserFrosting

  Sources   Download

MIT

The Requires

 

The Development Requires

configuration config userfrosting

18/06 2017

dev-develop

dev-develop https://github.com/userfrosting/config

Configuration module for UserFrosting

  Sources   Download

MIT

The Requires

 

The Development Requires

configuration config userfrosting

05/03 2017

4.0.1

4.0.1.0 https://github.com/userfrosting/config

Configuration module for UserFrosting

  Sources   Download

MIT

The Requires

 

configuration config userfrosting

18/02 2017

4.0.0

4.0.0.0 https://github.com/userfrosting/config

Configuration module for UserFrosting

  Sources   Download

MIT

The Requires

 

configuration config userfrosting

01/06 2016

1.1

1.1.0.0 https://github.com/userfrosting/config

Configuration module for UserFrosting

  Sources   Download

MIT

The Requires

 

configuration config userfrosting

29/03 2016