Skip to content
KorvinSzanto edited this page Oct 13, 2014 · 5 revisions

Introduction

In concrete 5.7 the configuration has been completely overhauled. Gone are the days where constants are slung about, in the name of configuration. Instead, we now have a new way for setting, and retrieving configuration options, which are fully overridable, and are hierarchical in design.

The new configuration “key” consists of 3 parts:

  • Namespace - This will be blank for core configurations, or the package handle for any package configurations.
  • Group - The group that the config item belongs to.
  • Item - The index of the configuration key The above parts can be used to look up the value of the configuration.

Configuration Hierarchy

The new configuration allows for configuration settings to be nested in groups.

Config File Loading hierarchy

https://github.com/concrete5/concrete5-5.7.0/blob/develop/tests/tests/Core/Config/FileLoaderTest.php

// This should be helpful in understanding how environments work. Defining them is done in /application/bootstrap/start.php

Load group $group namespace null:

/concrete/config/{$group}.php
/application/config/generated_overrides/{$group}.php
/application/config/{$group}.php
/application/config/{$environment}/{$group}.php

Load group $group namespace $namespace

/application/config/generated_overrides/{$namespace}/{$group}.php
/application/config/{$namespace}/{$group}.php
/application/config/{$environment}/{$namespace}/{$group}.php

Just notes below here

// Read / Write methods

\Config::get(‘my.local.test’, $default=null)
\Config::has(‘my.local.test’)
\Config::set(‘my.local.test’, ‘abc’)
\Config::save(‘my.local.test’, ‘abc’)

The group is important because it is the "index" on which the configuration gets zipped up. \Config::get(‘group.item.item.item’) will do something like this:

if ($this->hasGroupCached('group')) {
    $group = $this->getCachedGroup('group');
} else {
    $group = $this->getConfigLoader()->loadGroup('group');
    $this->cacheGroup('group', $group);
}
return array_get($group, 'item.item.item');

Key spec: (see these examples)

/^(?:(?P<Namespace>.+?)::)?(?P<Group>[^.]+).(?P<Item>.+)$/

Valid Key Examples:

  • namespace::group.item
  • group.item

Half valid keys (Can’t write scalar values)

  • namespace::group
  • group

Invalid keys

  • namespace

cache.levels.expensive.drivers

Namespace = NULL
Group     = cache
Item      = levels.expensive.drivers

At this point, a saved config VALUE needs to have two things: a group and an item. It can optionally be namespaced.

if I do \Config::save(‘group’, ‘value’); it should either case to an array and save as group.1 => ‘value’ or throw an exception, since the value doesn’t have the two required things.

Clone this wiki locally