Configuration module for UserFrosting

4.5.0 2021-04-21 00:50 UTC

This package is auto-updated.

Last update: 2024-04-21 07:05:16 UTC


Latest Version Software License Join the chat at Donate

Branch Build Coverage Style


Create a file default.php, in a directory /path/to/core/config/:


return [
    'contacts' => [
        'housekeeper' => [
            'name' => 'Alex',
            'email' => ''

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:


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.

Path builder

Create ResourceLocator and ConfigPathBuilder classes to build a list of configuration files:

$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:

Data loader

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

$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:

echo $config->get('');
// 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:


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

To merge this in, you would call:

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

Style Guide